• Microsoft Windows 10 Home, Version 1803 (Build 17134.523)
  • Microsoft Office Professional Plus 2016
  • Microsoft Outlook 2016, Version 1812 (Build 11126.20266)

Outlook setup (mail addresses anonymized):

  • Outlook is connected to the mailboxes "Master@provider1.net", "Business@provider2.net", "Private@provider2.net" and to the archive "Archive".
  • The mailboxes use IMAP/SMTP. Associated OST-files are locally available. The archive is a local PST-data file.
  • The mailbox "Master@provider1.net" was the first one which was connected to Outlook, then the mailboxes "Private@provider2.net" and "Business@provider2.net" and finally the archive "Archive".
  • The Outlook navigation panel shows the mailboxes and the archive in the sequence "Master@provider1.net", "Archive", "Business@provider2.net", Private@provider2.net, i.e. the initially connected mailbox at the top, then the archive and other mailboxes in alphabetical order.
  • The mailbox "Master@provider1.net" is set up as “standard mailbox“ in the outlook mailbox settings.

Test job: Display all elements contained in the respective mailbox or archive in a search folder named “TEST“ which is created using VBA.

VBA code:

Sub CreateSearchFolders_TEST()
  Dim MyFolder As Folder
  Dim MyScope  As String
  Dim MySearch As Search

  For Each MyFolder In Application.GetNamespace("MAPI").Folders
      Debug.Print MyFolder.Name

  Set MyFolder =   Application.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Parent
  MyScope = "'" & MyFolder.FolderPath & "'"

 'MyScope = "'\\Master@provider1.net'"
 'MyScope = "'\\Business@provider2.net'"
 'MyScope = "'\\Private@provider2.net'"
 'MyScope = "'\\Archive'"
 'MyScope = "'\\Archive\Input','\\Archive\Sent'"

  Set MySearch = Application.AdvancedSearch _
  (Scope:=MyScope, Filter:="", SearchSubFolders:=True, Tag:="MySearchFolder")
  MySearch.Save ("TEST")

End Sub


  • The FOR-loop firstly lists the mailboxes "Business$provider2.net", "Master@provider1.net", "Private@provider2.net" in alphabetical order and finally the "Archive".
  • The above VBA-code creates the desired search folder "TEST" in "Master@provider1.net", i.e. as expected.
  • The code also works if the line

    MyScope = "'" & MyFolder.FolderPath & "'"

    is commented out and the line

    'MyScope = "'\\Master@provider1.net'"

    is activated instead.

  • However, if one line out of the lines

    'MyScope = "'\\Business@provider2.net'"
    'MyScope = "'\\Private@provider2.net'"
    'MyScope = "'\\Archive'"

    is activated instead, execution stops at the line

    MySearch.Save ("TEST")

    with the following error message:

    Run time error -2147221241 (80040107)': Procedure could not be executed. No object found.

  • If the line

    'MyScope = "'\\Archive\Input','\\Archive\Sent'"

    is activated instead, the code works but merely yields the contents of the subfolders "Input" and "Sent" - just as expected.

  • If "Archive" is replaced with e.g. "Private$provider2.net" in this line, the code also works with this mailbox, but expectedly yields the contents of the stated subfolders "Input" and "Sent“ only.

Obviously there is a difference between individual mailboxes as well as between mailboxes and archives. One mailbox appears to be privileged. Tentatively declaring other mailboxes as „standard mailbox“ in the outlook mailbox settings does not change the result of code execution.

Where can I find a documention of this difference?

What is the cause for this difference?

What needs to be changed in the code in order to make it work with all mailboxes and archives?

Simply using MyScope which provides all folders contained in a mailbox or archive does not solve the problem. A search folder created this way would yield incomplete results or even fail whenever folders are added, deleted or renamed later on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.