Forum Discussion
Moving of outlook mails from specific sender to specific sub-folder via excel
I could able to loop sender names from excel range (a2:a3) but i am unable to loop folder names from excel range (b2:b3), to send specific sender mails to specific folder.
anyone have any idea how i can complete this code ? or if you have any solution please let me know.
its urgent .. please help experts ..!!!!
Sub MoveItems()
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Outlook.Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Meetings")
Dim varSearchTerms As Variant
varSearchTerms = Range("a2:a3").Value ' Array looped via excel range
Dim varSearchTerm As Variant
For Each varSearchTerm In varSearchTerms
Set myItem = myItems.Find("[SenderName] = '" & varSearchTerm & "'")
While TypeName(myItem) <> "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
Next
End Sub