Search and Find Email by Folder Name

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Hello Diana,

Can you please help me as I am stuck with this code? I extracted it from the Sub SearchByAddress Use Instant search to find messages from a contact and changed it a bit so that the Search finds the foldername instead of contact. I get the result, but rather than FullFolderPath I need to have results display in Search Bar as only Folder name, instead of FullFolderPath. In the screenshot uploaded, the Search macro displays the entire result, like "*******@domain.com/Inbox", but I need need it only display Inbox path, i.e. only the folder name the email is stored.

Code:

*****
Sub SearchByFolder()
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.Parent.FullFolderPath

Set myOlApp.ActiveExplorer.CurrentFolder = NS.GetDefaultFolder(olFolderInbox)
txtSearch = "folderpath: ( " & Chr(34) & strFilter & Chr(34) & ") "
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllOutlookItems

Set myOlApp = Nothing
End Sub
****

Screenshot 2022-01-07 094932.png
 

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Hello, any feedback please?

Regards
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry, I didn't see this earlier. You can't search for a folder name, only search within a folder.
This searches the inbox - folderpath:Inbox

Try this macro - it finds a folder by name.
 
Similar threads
Thread starter Title Forum Replies Date
J search doesn't find anything Using Outlook 1
B Looking to filter (or just find/search) for only messages that the sender has sent more than 1 messa Using Outlook 2
B Search: Cannot find which Folder Contains a Message Using Outlook 3
K Re: Use Instant search to find messages from a contact Outlook VBA and Custom Forms 6
R writing "Instant Search" queries to find User-Defined fields Using Outlook 0
T Outlook 365 Search Box reverting to old location Using Outlook 3
P Outlook 2013 search no longer works Using Outlook 2
C How to search for items in Outbox with multiple accounts? Using Outlook 14
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
A Any way to force sort by/group by on search results with VBA? Outlook VBA and Custom Forms 1
C Search not accurate, but not indexing Using Outlook 9
J How do you disable address search box when typing @ in body of email? Using Outlook 0
H Outlook 2019 intermittent search results Using Outlook 0
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
mll persistently customise columns in outlook advanced search Using Outlook 3
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
S VBA search string with special characters Outlook VBA and Custom Forms 1
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
O Advanced search - can I use booleans Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
M Something went wrong and your search couldn't be completed Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
L New Location for the Search Bar Using Outlook 6
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
J Outlook 2016 After a search in all mailboxes, where is each message that was found? Using Outlook 6
King Mustard Sort search groups by amount of items? Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
T Search for incoming e-mails for a specified time range Using Outlook 1
S outlook 2007 calendar search Using Outlook 6
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
J Message search and edit, another way? Outlook VBA and Custom Forms 4
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
A Outlook 2019 having issues with 'people search' and not making suggestions in email To: etc Using Outlook 12
W Search Incomplete Outlook 2016 Using Outlook 5
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
R outlook address book search broken Using Outlook 2
K Outlook.com is not showing, or finding via search, all my Contacts (People) Using Outlook 0
W Create Search Folder excluding Specific Email Addresses Using Outlook 5

Similar threads

Top