im getting a type mismatch error

cale may

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Hello,

I want to filter my inbox by searching for a single persons name.

I have done my best to follow the instructions on getting this vba code to run:

Sub SearchByAddress()
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:(kirsten collins)" & strFilter
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
Set myOlApp = Nothing
End Sub

I get a type mismatch error on the "Set oContact = ActiveExplorer.Selection.Item(1)" line

Could someone please help?
 

cale may

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
No. I didn't understand that part. I will try tomorrow.
Is there a macro that I can set up for a person's name.
I spend 1 hour a day filtering by peoples names. I would like to find a macro that I can click and it does it for me.
Thank You so much for your help.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange

Top