AdvancedSearch help

wtnelso

Board Regular
Joined
Feb 15, 2012
Messages
241
I'm trying to do an advanced search in MS Outlook 2010 for a MailItem using advanced search. The issue I'm having is searching through subfolders. I know that the third argument in the function is a boolean for searching through those folders, but I'm having no luck. So what I want to do is have an array for the scope (the first argument) which lists the folder names.

The array is very easy when searching main folders ('Inbox','Contacts','Calendar'), but the issue is how to use that same format to list subfolders, for instance, "'Inbox\Subfolder1','Inbox\Subfolder2'". Simply listing the subfolder names in the array as stand alone names causes the function to fail. How could I accomplish listing these names? Or is there any easier way to accomplish the same search without needing to do this? Below is what I have so far with our the Declarations of variables, etc...

Code:
    Const strScope As String = "'Inbox', 'Inbox\SubFolder1', 'Inbox\SubFolder2','Inbox\SubFolder3'" 'Need help here
    
    strSubject = oMail.ConversationTopic
    strF = "urn:schemas:mailheader:subject =  '" & strSubject & "'"
    strTag = "SubjectSearch"
    Set objSch = Application.AdvancedSearch(strScope, strF, True, strTag)
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top