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.
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:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor