Per our earlier posts, we created a macro that searches all e-mails to or from the contact that we select or open, and the macro bullet is in the Outlook Toolbx and in the Contact form itself.
But now, it works if the contact is opened, but not where I just select the contact.
The error that shows up is:
The macro error is:
Run-time error '91':
Object variable or With block variable not set.
And when I debug, the line Set oContact = myOlApp.ActiveInspector.CurrentItem is yellowed...'
'
Is there a way to fix this right away?
And the full macro you gave me 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 = myOlApp.ActiveInspector.CurrentItem
' 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
Thanks
But now, it works if the contact is opened, but not where I just select the contact.
The error that shows up is:
The macro error is:
Run-time error '91':
Object variable or With block variable not set.
And when I debug, the line Set oContact = myOlApp.ActiveInspector.CurrentItem is yellowed...'
'
Is there a way to fix this right away?
And the full macro you gave me 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 = myOlApp.ActiveInspector.CurrentItem
' 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
Thanks