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
Hello Diana,
I am not sure if you received the request - I submitted it yesterday. I am re-submitting it.
Dear Diana,
The code runs just perfect – may I ask for assistance, I need to slightly modify the code so that it may find email sent (throughout the entire mailbox, including the pst folders) yesterday and only from one certain account. How may it be re-edited so that it meets the requirements?
Sorry I missed this earlier. You need to change the filter to add received date and account (I think account will work - it is working here in the Instant Search field)
txtSearch = "[Conversation]:=""" & strSubject & """ (to:(" & strFrom & ") OR from:(" & strFrom & ")) & "received:yesterday account:(account@domain.com)"
How do I find and group conversations that have similar values in the subject and/or message?
Subject Example(s):
Request: 1234
Request: 1234 Close
Request: 1234 Ship
Request: 4321
Request: 4321 Close
Request: 4321 Ship
Is there a Macro Code, you could provide that would search a specific folder, for message that has already been replied to (such as emails sent a distribution) list and move them to a new folder?
Common rule setting will now allow this, or maybe I missed it.
Thank you in advance
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.
Yeah, it looks like something is missing - the parenthesis are mismatched. Thanks for letting me know.