0

I have a macro that reads the subject line of an email, finds the UID and copies it to the clipboard. I then search Outlook for the UID and highlight certain emails. I want to send them all to a folder.

I have the loop and move worked out, but it only moves the active/selected email. How do I have move all of the highlighted emails and not just the selected email?

Select Case Outlook.Application.ActiveWindow.Class
    Case olInspector
        Set myItem = ActiveInspector.CurrentItem
    Case olExplorer
        Set myItem = Application.ActiveExplorer.Selection.Item(1)
End Select

myItem.Move objNS.GetDefaultFolder(olFolderInbox).Folders(strSubFolder1)

I'm using the terms "active" and "selected" interchangeably which may be inaccurate. By active or selected I mean the email that is being displayed in the reading pane.

enter image description here

karel
  • 5,489
  • 46
  • 45
  • 50
pebcak
  • 13
  • 2

1 Answers1

0

.Item(1) means you only work with one item - try moving each item in the Selection instead

Dim objNS As NameSpace, itm, sel As Object, i As Long
Dim dest As Folder

Set objNS = Application.GetNamespace("MAPI")

Set dest = objNS.Folders(1).Folders("Test")

Select Case Outlook.Application.ActiveWindow.Class
    Case olInspector
        ActiveInspector.CurrentItem.Move dest
    Case olExplorer
        Set sel = Application.ActiveExplorer.Selection
        For i = sel.Count To 1 Step -1
            sel(i).Move objNS.Folders(1).Folders("Test")
        Next i
End Select
Tim Williams
  • 154,628
  • 8
  • 97
  • 125