JonnyAMP
01-25-2016, 07:35 AM
I apologize if this has been posted but my searches didn't find anything.
I have a macro that deletes all emails in a folder from a particular sender. In order to delete from multiple senders I end up copying the same few lines as I can't figure out how to loop with a list. Thanks in advance.
Sub ResearchPurge_From_Trash()
Dim myNameSpace As Outlook.NameSpace
Dim myDelItemsBox As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set myDelItemsBox = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
Set myItems = myDelItemsBox.Items
Set myItem = myItems.Find("[SenderEmailAddress] = 'first1.last1....'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
Set myItem = myItems.Find("[SenderEmailAddress] = 'first2.last2....'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
Set myItem = myItems.Find("[SenderEmailAddress] = 'first3.last3...'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
End Sub
I have a macro that deletes all emails in a folder from a particular sender. In order to delete from multiple senders I end up copying the same few lines as I can't figure out how to loop with a list. Thanks in advance.
Sub ResearchPurge_From_Trash()
Dim myNameSpace As Outlook.NameSpace
Dim myDelItemsBox As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set myDelItemsBox = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
Set myItems = myDelItemsBox.Items
Set myItem = myItems.Find("[SenderEmailAddress] = 'first1.last1....'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
Set myItem = myItems.Find("[SenderEmailAddress] = 'first2.last2....'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
Set myItem = myItems.Find("[SenderEmailAddress] = 'first3.last3...'")
While TypeName(myItem) <> "Nothing"
myItem.Delete
Set myItem = myItems.FindNext
Wend
End Sub