Hi Everybody.
I'm trying to write a macro to delete all of the emails that come up from a search result and I'm having problem with it. I'm wondering if one of you can give me some assistance.
Here is what I'm doing. I select an email and run the macro which extracts the email address from the selected email, then perform a search for all emails from the same sender within the folder. What I can't figure out is how to programatically select all of those emails and delete them. Here is what I have so far.
Sub FindAllEmailsFromSender()
I'm trying to write a macro to delete all of the emails that come up from a search result and I'm having problem with it. I'm wondering if one of you can give me some assistance.
Here is what I'm doing. I select an email and run the macro which extracts the email address from the selected email, then perform a search for all emails from the same sender within the folder. What I can't figure out is how to programatically select all of those emails and delete them. Here is what I have so far.
Sub FindAllEmailsFromSender()
Dim objMail As Outlook.MailItem
Set objMail = Outlook.Application.ActiveExplorer.Selection.item(1)
Dim strSenderEmailAddr As String
strSenderEmailAddr = objMail.SenderEmailAddress
Dim myOlApp As New Outlook.Application
Set myOlApp.ActiveExplorer.CurrentFolder = Application.ActiveExplorer.CurrentFolder
txtSearch = "from:" & strSenderEmailAddr
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeCurrentFolder
Set myOlApp = Nothing
End SubSet objMail = Outlook.Application.ActiveExplorer.Selection.item(1)
Dim strSenderEmailAddr As String
strSenderEmailAddr = objMail.SenderEmailAddress
Dim myOlApp As New Outlook.Application
Set myOlApp.ActiveExplorer.CurrentFolder = Application.ActiveExplorer.CurrentFolder
txtSearch = "from:" & strSenderEmailAddr
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeCurrentFolder
Set myOlApp = Nothing