Find messages in a conversation

Last reviewed on March 5, 2014

A client had a problem: when he uses Instant Search to find messages from a person, the results contain only messages from that person, not all messages in the conversation, and he needs an easy way to find his replies. Yes, he could use Find Related, but it's less than accurate (as seen in the screenshot below), matching other messages with the same words in the subject.

Find Related Messages

A better Instant search query would look for messages to or from the person and match the subject. This Instant Search query:

[Conversation]:="Hotmail Outlook Problem" (to:(missy) OR from:(missy))

Finds only messages in the conversation, but it's a lot more typing to create on the fly. It is well suited to use in a macro though.

This macro works on a message selected in the message list and displays the results in the Inbox folder. See Outlook VBA: work with open item or selected item for function that will allow this to work with open or selected messages.

Search for messages in a conversation macro

Sub SearchForConversations()
 
Dim myOlApp As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim strFrom, strSubject As String
Dim oMail  As Outlook.MailItem
 
Set ns = myOlApp.GetNamespace("MAPI")
 
Set oMail = ActiveExplorer.Selection.Item(1)
 
' use oMail.SenderEmailAddress to search on the address
strFrom = oMail.SenderName
strSubject = oMail.ConversationTopic
  
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
 
txtSearch = "[Conversation]:=""" & strSubject & """ (to:(" & strFrom & ") OR from:(" & strFrom & "))"

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
 
Set myOlApp = Nothing
 
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Written by

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.

Please post long or more complicated questions at Outlookforums.

2 responses to “Find messages in a conversation”

  1. joe

    Elegant macro! Thanks. I noticed a small typo. Change from this:
    """ to:("
    To this:
    """ (to:("

    That way, the whole To OR From clause is enclosed in parentheses.

Leave a Reply

If the Post Coment button disappears, press your Tab key.