views:

313

answers:

0

I'm trying to add a Public Folder to Outlook 2007's Favorite Folders list using VBScript.

This is what I've hacked together using code I found in an Experts Exchange article:

Const olPublicFoldersAllPublicFolders = 18
Const olMailModule = 158
Const olFavoriteFoldersGroup = 4

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNameSpace("MAPI")
objNS.Logon "Outlook"

#'Get the Favorites group
Set objPane = objOL.ActiveExplorer.NavigationPane
Set objModule = objPane.Modules.GetNavigationModule(olModuleMail)
Set objGroup = objModule.NavigationGroups.GetDefaultNavigationGroup(olFavoriteFoldersGroup)

#'Add folder to Public Folder Favorites
Set objFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Folder Name")
objFolder.AddToPFFavorites

#'Add the folder to Folder Favorites
Set objFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Parent.Folders("Favorites"). _
    Folders("Folder Name")
objGroup.NavigationFolders.Add objFolder

objNS.Logoff

I would like to use this as a startup script but it only works if Outlook is open and in the Mail view.

I'm guessing that some code to change to the Mail NavigationModule might work but I haven't found any way to do this.