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
****
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
****