Search notes:

Outlook Object Model: Application.AdvancedSearch

option explicit

sub main() ' {

    dim scope as string
        scope = "'" & session.getDefaultFolder(olFolderInbox   ).folderPath & "'," & _
                "'" & session.getDefaultFolder(olFolderSentMail).folderPath & "'"

    dim query as string
        query = "urn:schemas:mailheader:subject = 'XYZ'"

    advancedSearch scope, query, searchSubFolders := false, tag := "tq84"

end sub ' }
Github repository about-MS-Office-object-model, path: /Outlook/Application/advancedSearch/main.vb
option explicit

private sub application_advancedSearchComplete(byVal found as search) ' {
  '
  ' Put this event into 'ThisOutlookSession' module
  '
    debug.print "search with tag " & found.tag & " completed"

  '
  ' dim tab as table
  ' set tab = found.getTable

    dim email as mailItem
    for each email in found.results
         email.display
    next email

end sub ' }
Github repository about-MS-Office-object-model, path: /Outlook/Application/advancedSearch/advancedSearchComplete.vb

See also

When the advancedSearch() method complets, the application.advancedSearchComplete event is triggered.
Outlook Object Model: applying filters

Index