Starting situation:
Outlook 2016 is connected to the mailbox "Name@Domain"
and a local "Archive"
. The mailbox uses IMAP/SMTP and a local OST-file. "Archive"
is a local PST-file.
Test job:
Display all elements contained in the mailbox or archive in a search folder named "TEST"
which is created using VBA:
Public FlagAdvancedSearchComplete As Boolean
Private Sub Application_AdvancedSearchComplete (ByVal SearchObject As Search)
FlagAdvancedSearchComplete = True
End Sub
Sub CreateSearchFolder_TEST()
Dim MyScope As String
Dim MySearch As Search
MyScope = "'\\Name@Domain'"
'MyScope = "'\\Archive'"
Set MySearch = Application.AdvancedSearch _
(Scope:=MyScope, Filter:="", SearchSubFolders:=True, Tag:="MySearchFolder")
Do While FlagAdvancedSearchComplete = False
DoEvents
Loop
MySearch.Save ("TEST")
End Sub
Findings:
The VBA-code creates the desired search folder "TEST"
in "Name@Domain“
as expected. However, if MyScope = "'\\Archive'"
is activated instead of 'MyScope = "'\\Name@Domain‘"
execution stops at the line MySearch.Save ("TEST")
with the following error message:
Run time error -2147221241 (80040107):
Procedure could not be executed. Object not found.
What needs to be changed in the code in order to make it work with all mailboxes and archives?