问题
I'm working now on Outlook macros to add selected folder to Outlook's favorites group. I've tried to use this method
Sub AddToFavorites()
Dim olapp As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Set olapp = New Outlook.Application
Set objFolder = olapp.ActiveExplorer.CurrentFolder
objFolder.AddToPFFavorites
End Sub
But AddToPFFavorites method throws error "The attempted operation failed. An object could not be found".
I've tried to add target folder to favorites using "Show in Favorites" action from context menu, as result folder has been showed in Favorites group without errors.
My question is: How to add folder to favorites group? What is VBA equivalent for "Show in Favorites" action?
回答1:
You can manage the Outlook favorites group by accessing the NavigationPane mail module.
Outlook.MailModule mailModule = ThisAddIn.Application.ActiveExplorer().NavigationPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleMail) as Outlook.MailModule;
Outlook.NavigationGroup favGroup = mailModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olFavoriteFoldersGroup);
favGroup.NavigationFolders.Add(objFolder);
来源:https://stackoverflow.com/questions/12935579/outlook-add-folder-to-favorites-group