Per an earlier post, I learned to create a macro that for any contact I identify or open up, it will search or all emails From or To that contact. And that works great.
But, when I create a calendar event and add a shortcut to the contact, and I open the contact from that shortcut, the macro to search for emails does not work and in the debug, it colors the words:
Set oContact = ActiveExplorer.Selection.Item(1)
So there way to fix this so when I open up the contact from a shortcut to the calendar event, it will also do the search?
Thanks so much.
And the full macro is:
Sub Search_By_Address_From_and_To()
Dim myOlApp As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim strFilter As String
Dim oContact As Outlook.ContactItem
Set ns = myOlApp.GetNamespace("MAPI")
Set oContact = ActiveExplorer.Selection.Item(1)
' use oContact.FullName to search on the name
strFilter = oContact.Email1Address
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
txtSearch = "from:" & strFilter & " OR to:" & strFilter
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
Set myOlApp = Nothing
End Sub
But, when I create a calendar event and add a shortcut to the contact, and I open the contact from that shortcut, the macro to search for emails does not work and in the debug, it colors the words:
Set oContact = ActiveExplorer.Selection.Item(1)
So there way to fix this so when I open up the contact from a shortcut to the calendar event, it will also do the search?
Thanks so much.
And the full macro is:
Sub Search_By_Address_From_and_To()
Dim myOlApp As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim strFilter As String
Dim oContact As Outlook.ContactItem
Set ns = myOlApp.GetNamespace("MAPI")
Set oContact = ActiveExplorer.Selection.Item(1)
' use oContact.FullName to search on the name
strFilter = oContact.Email1Address
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
txtSearch = "from:" & strFilter & " OR to:" & strFilter
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
Set myOlApp = Nothing
End Sub