• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Use Instant search to find messages from a contact

Slipstick Systems

› Developer › Use Instant search to find messages from a contact

Last reviewed on June 12, 2021     21 Comments

Applies to: Outlook (classic), Outlook 2007, Outlook 2010

Older versions of Outlook have the Activities tab which will find all Outlook items associated with a particular contact. Activities are broken in Outlook 2010 and removed from Outlook 2013.

While you can use the Social Connector's People pane to see all messages, appointments, and attachments from a person, you can also use Instant Search. Type from:(name) or from:(email@address) in the Instant search field.

Instant Search field

This macro makes it easier to use Instant Search to find messages for a selected contact, by entering the contact's name or email address into the Instant Search field in the Inbox.

If you need persistent search results, see How to create an Outlook search folder using VBA.

This macro can use any valid Instant search criteria. You just need to replace or edit the txtSearch line. To find messages to and from a contact, use txtSearch = "from:" & strFilter & " OR to:" & strFilter

Search for messages from contact macro

  1. Open the VBA editor using Alt+F11
  2. Right click on Project1 and choose Insert > Module
  3. Paste the following code into the module.
  4. Set macro security to low to test the code, then use Selfcert to sign the macro before change security to high.
  5. Add the macro to a ribbon, QAT, or toolbar button.
  6. Select a contact and run the macro.

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:" & strFilter
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub

 

Search for messages to or from a sender

This version of the code creates an instant search for all messages to or from the sender, including messages you sent.

To use, select a message and run the macro. An instant search for messages to or from the person's email address is created.

Sub SearchByAddress()
 
Dim myOlApp As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim strFilter As String
Dim oMail  As Outlook.MailItem
 
Set ns = myOlApp.GetNamespace("MAPI")
 
Set oMail = Application.ActiveExplorer.Selection.Item(1)
      strFilter = oMail.SenderEmailAddress
  
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
     txtSearch = "from:(" & Chr(34) & strFilter & Chr(34) & ") OR to:(" & Chr(34) & strFilter & Chr(34) & ")"
     myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
 
Set myOlApp = Nothing
 
End Sub

 

Search for All Contact Addresses

This version of the macro search for messages from all three email addresses on a contact, if additional addresses exist.

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 = Chr(34) & oContact.Email1Address & Chr(34)

If oContact.Email2Address <> "" Then
strFilter = strFilter & " OR " & Chr(34) & oContact.Email2Address & Chr(34)
End If

If oContact.Email3Address <> "" Then
strFilter = strFilter & " OR " & Chr(34) & oContact.Email3Address & Chr(34)
End If
  
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)

txtSearch = "from:(" & strFilter & ") OR to:(" & strFilter & ")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
 
Set myOlApp = Nothing
 
End Sub

 

Search Journal

If you are still using Journal, you can tweak the macro to search the journal for items associated with the contact. Change the contact field to Full name and the folder to journal.

strFilter = oContact.FullName
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderJournal)

' change the search filter to look for the contact name
txtSearch = "contactnames:(" & strFilter & ")"

Valid Search Scopes

Outlook 2010 and Outlook 2013 use the following search scopes:

ScopeDescription
olSearchScopeCurrentFolderLimit the search to the currently selected folder.
olSearchScopeSubfoldersLimit the search to the currently selected folder and its subfolders. To search all folders in one data file, select the top level of the pst.
olSearchScopeAllFoldersSearch all folders (of the current folder type). This search includes all data stores that are enabled for search.
olSearchScopeAllOutlookItemsSearch all Outlook items in all folders in stores that are enabled for search.

Outlook 2007 users are are limited to olSearchScopeAllFolders and olSearchScopeCurrentFolder.

More Information

How to Create a Unified Inbox View
How to create an Outlook search folder using VBA
Instant Search Queries

Use Instant search to find messages from a contact was last modified: June 12th, 2021 by Diane Poremsky

Related Posts:

  • Find messages in a conversation
  • How to Create a Unified Inbox View
  • Create an Outlook Search Folder for Sender
  • Search for All Messages from Contact and Display in New Window

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
21 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

sapana (@guest_207561)
July 5, 2017 12:22 pm
#207561

This code was really helpful for me. thank you for posting it here.
I need go one more step ahead, to copy the search result emails onto the hard drive.
I would really appreciate if someone could help me....

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  sapana
July 7, 2017 12:45 am
#207574

The easiest way, if you don't need to do this "all the time" is to select all and copy (ctrl+a, c) then paste into a folder on the hard drive.

If you need to use a macro, you'll need to get a count of messages then use a loop to work through them - once you do that, saving is easy. (You will probably need to walk every folder and check the recipients - I'm not sure if you can loop the search results.)
https://www.slipstick.com/developer/code-samples/save-selected-message-file/

0
0
Reply
Michael (@guest_204897)
February 27, 2017 5:52 am
#204897

How can I show all tasks associated with a contact?

I changed the macro to use:
txtSearch = "contactnames:(" & strFilter & ")"

but it will show no results

the full code:
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.FullName

Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderTasks)

txtSearch = "contactnames:(" & strFilter & ")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Michael
March 4, 2017 1:44 am
#205011

Fails here too, using contact and contacts too - i know they broke some aspects of the contact linking feature and if they are indexing that field search won't work in Tasks. (The contact search should work for mail.)

0
0
Reply
Henrik (@guest_203149)
November 29, 2016 2:35 pm
#203149

Thanks for posting all these great code examples. I have tried to get the "Search for messages to or from a sender" variant to work, but the search string coming out of the macro looks very strange. The strFilter string starts with /O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP...? (I am running Outlook 2013). Thanks in advance for your help :-)

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Henrik
March 4, 2017 1:37 am
#205010

That is the Exchange x.500 address - it's only used internally. In Rules, you'd look for "/OU" in the address... not sure if it will work with instant search.

0
0
Reply
Hannah (@guest_197263)
March 17, 2016 3:05 pm
#197263

I'm not sure if this is where I should put this or not -- but I'm looking to do a global find in outlook for a category -- across tasks & email. Is that possible, or do I have to do two searches (one in mail and another in tasks)?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Hannah
March 18, 2016 7:50 am
#197274

One of the instant search scopes is all outlook items - that will include calendar and contacts, but if the category isn't used there, it won't find anything. It is is possible to include a message class, which would limit it to tasks and mail.

0
0
Reply
JBG (@guest_193858)
October 9, 2015 8:30 am
#193858

Diane, Where in this program should I change or add the Set oContact command line you recommend? Please review and modify how this code should read to get the button to wok on an Opened Outlook Contact Form: Sub FindContactActivities() If Application.Session.DefaultStore.IsInstantSearchEnabled Then Dim olkExplorer As Outlook.Explorer Set olkExplorer = Application.Explorers.Add(Application.Session.GetDefaultFolder(olFolderInbox), olFolderDisplayNormal) Dim oItem As Object Set oItem = Application.ActiveInspector.CurrentItem If oItem.Class = olContact Then Dim myContact As Outlook.ContactItem Set myContact = oItem Dim myContactAddress As String Dim myContactName As String myContactAddress = myContact.Email1Address myContactName = myContact.FullName Dim olkFilter As String 'Linked Contacts olkFilter = "contactnames:(" & Chr(34) & myContactAddress & Chr(34) & " OR " & Chr(34) & myContactName & Chr(34) & ")" 'From this contact olkFilter = olkFilter & " OR " & "from:(" & Chr(34) & myContactAddress & Chr(34) & " OR " & Chr(34) & myContactName & Chr(34) & ")" 'To this contact olkFilter = olkFilter & " OR " & "to:(" & Chr(34) & myContactAddress & Chr(34) & " OR " & Chr(34) & myContactName & Chr(34) & ")" Call olkExplorer.Search(olkFilter, olSearchScopeAllOutlookItems) Call olkExplorer.Display Else MsgBox "Please run this command from an opened Contact item.", vbExclamation, "Open a Contact item" End If Set olkExplorer =… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  JBG
October 9, 2015 10:21 am
#193861

your code uses oitem as the contact object, not ocontact, and already uses the current item:
Set oItem = Application.ActiveInspector.CurrentItem

in my code, you'd change
Set oContact = ActiveExplorer.Selection.item(1)
to
Set oContact = Application.ActiveInspector.CurrentItem

The code works here. it's hard to say what is wrong.
Video of my macro in action is here (when its finished processing) - https://drive.google.com/file/d/0B22iPSInt7uxYmZGMHJUZVJMWVk/view?usp=sharing

0
0
Reply
JBG (@guest_193801)
October 6, 2015 9:42 pm
#193801

Diane,

I left this question on another page already so forgive the duplication.
I have the search macro done and it works in the VBA Editor Run function, but the button I added to the Contact Screen ribbon and QAT do not work. Nothing at all seems to be happening. I did a self certificate for the VBA, but I also tried removing Marco security and nothing has fixed it.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  JBG
October 6, 2015 10:01 pm
#193803

It works with selected contacts as written, not opened contacts. It should work if the button is on the main outlook ribbon or QAT. Changing the line to Set oContact = myOlApp.ActiveInspector.CurrentItem will make it work with an open contact.
https://www.slipstick.com/developer/outlook-vba-work-with-open-item-or-select-item/

0
0
Reply
Kay C (@guest_187838)
November 26, 2014 12:24 pm
#187838

HI, Can you make your macro work for all the email addresses on record in the contact instead of just the first one? Plus, can you make it show all sent AND received emails from all the contact's email addresses. This would truly mimic the defunct "show activities" feature.

0
0
Reply
Diane Poremsky (@guest_187839)
Reply to  Kay C
November 26, 2014 12:40 pm
#187839

All addresses: Yes. This line needs edited - strFilter = oContact.Email1Address - to include all fields (email2address, email3address)
strfilter = chr(34) & oContact.Email1Address & chr(34) & " OR " & chr(34) & ocontact.email2address & chr(34) & " OR " & chr(34) & ocontact.email3address & chr(34)
txtSearch = "from:(" & strFilter & ")"

the chr(34) adds double quotes so mary@domain.com doesn't find all instances of mary, domain, and com. if you want to search both from and body, remove From: from the search string.

0
0
Reply
Diane Poremsky (@guest_187853)
Reply to  Kay C
November 26, 2014 5:55 pm
#187853

As an FYI, i updated the page to include a macro that uses all 3, if the fields contain an address. https://www.slipstick.com/developer/instant-search-messages-selected-contact/#all3

0
0
Reply
tomaszek926 (@guest_177751)
June 19, 2013 2:19 am
#177751

Hi,
Great macro, great article.
Especially, as as a user of IMAP accounts, i cannot use Activities - i use ONLY other pst data file, then default...
Really easy to implement and modify.
I have adapted it to Polish and to searching To: OR From: ....

One remark and question.
It works only while i check a contact on contact list.
Would be nice to have it also working when i open a contact form - sth like it was in O2007 (Activities - e-mail)
And best would be also to have it working on the list of e-mails (Inbox, for example).
I mean: i check an e-mail, and starting the macro i can have full history of e-mail communication with checked e-mail sender.....

Is it possible?

0
0
Reply
Diane Poremsky (@guest_177754)
Reply to  tomaszek926
June 19, 2013 5:04 am
#177754

You need to replace this:
Set oContact = ActiveExplorer.Selection.item(1)

with

Set objItem = GetCurrentItem()

and get the function from GetCurrentItem.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 16

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • Adjusting Outlook's Zoom Setting in Email
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Outlook SecureTemp Files Folder
  • Save Attachments to the Hard Drive
  • Add Attachments and Set Email Fields During a Mail Merge
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment