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
Thanks, a very useful macro. What would make it perfect for me is if it were possible to make it toggle - i.e. a second run of the macro restored the original (unfiltered) folder view. Any ideas please?
How to set different search scope folders ? kindly advice
Hello Diane,
Your codes run just perfectly, I have just changed though:
txtSearch = "[Conversation]:=""" & strSubject & """ (to:(" & strFrom & ") OR from:(" & strFrom & "))"
like into txtSearch = "[Conversation]:=""" & strSubject
as per my need, and that's it. From now on, no need to do:
right-click --->find related--->Messages in This Conversation anymore.
Thank you so much for your guidance.
all the best
Once again, an intelligent, direct, and practical/useful solution from Slipstick Systems to counter the Microsoft Deproductivity Dept. I was tearing my hair out trying to find the message that my Sent message replied to, as "Find Related" seems like it was written by a 9 year old. It apparently only does a silly text search for messages with the identical subject. When I change the subject, Find Related doesn't find it. And if you then view the message that my Sent message had replied to, you see "You replied to this message on 7/1/2021 12:22 PM.". You'd at least think, "Victory!", that if you clicked on that, it would go to your reply; clearly that sentence indicates that they have a database tree of messages, right? But it doesn't - that would be too logical and productive. (Yes, clicking on that is going in the opposite direction from my original quest, to find what "it replies to", not "what replies to it".) Nonetheless I've tried using Conversation and Subject: and Body: and wildcards and AND and OR and parentheses (and it can be an adventure because of search term processing inconsistencies), but all of this is just hunting and pecking… Read more Âğ
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.