'Change the Outlook account where to create a searchfolder with advancedsearch method and search object save method
I am using the Save method of the Search object that is returned by the advancedSearch method to create a Search Folder.
As I have multiple accounts in my Outlook, the search folder is always created under the same account (Default ?). Do you know if it is possible to change the account where I want the search folder to be created ?
Here is the code I am using that I found on the official MS documentation
Public blnSearchComp As Boolean
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
MsgBox "The AdvancedSearchComplete Event fired"
blnSearchComp = True
End Sub
Sub TestAdvancedSearchComplete()
Dim sch As Outlook.Search
Dim rsts As Outlook.Results
Dim i As Integer
blnSearchComp = False
Const strF As String = "urn:schemas:mailheader:subject = 'Test'"
Const strS As String = "Inbox"
Set sch = Application.AdvancedSearch(strS, strF)
While blnSearchComp = False
DoEvents
Wend
sch.Save("Subject Test")
End Sub
Solution 1:[1]
In OOM, you can enumerate existing search folders using Store.GetSearchFolders()
, but you cannot create search folders on the per-store basis.
If using Redemption (I am its author) is an option, you can use RDOFolder.Folders.AddSearchFolder to create a search folder anywhere and set its properties explicitly (the folder may or may not be visible to the user). You can also use RDOStore.Searches.AddCustom to create a search visible to the end-user under the "Searches" node in the folder tree view.
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Store = Session.Stores.DefaultStore 'can be any other store
set Searches = Store.Searches
strSQL = " Subject LIKE '%Test%'"
Dim excludedFolders(0)
excludedFolders(0) = olFolderJunk
set NewSearch = Searches.AddCustom("Test", strSQL, Store.IPMRootFolder, true, excludedFolders)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |