Outlook. Add folder to favorites group

旧街凉风 提交于 2019-11-28 04:02:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!