VBScript Automate Checking the "Show As Address Book" in Outlook 2010 and Above

Here is a simple script to automate marking the "Show As Address Book" for contact folders listed under the All Public Folders section in Outlook 2010 and above.
You may need to customize the code slightly if you need to mark more then one folder or need to access different folder(s) other then the first folder directly under the All public folder.

The Script

Function ShowAsAB()
'Create Outlook Application Object
Set AppObj = CreateObject("Outlook.Application")
'Use GetDefaultFolder Method to access All Public Folders
Set NSObj = AppObj.GetNamespace("MAPI").GetDefaultFolder(18)
'Access the first folder under the All Public Folders Section
Set fldrObj = NSObj.Folders(1)
'Access the first folder under the first folder under the All Public Folders Section
Set fldrSubObj = fldrObj.Folders(1)
'If not marked then mark it...
IF NOT fldrSubObj.ShowAsOutlookAB = True Then
fldrSubObj.ShowAsOutlookAB = True
End IF
End Function
'Call Function
ShowAsAB()

Script Explanation
The ShowAsAB function starts by creating an instance of the Outlook application object. With the application object and the GetDefaultFolder indexer 18 (ololPublicFoldersAllPublicFolders) to access the All Public Folders.
Review this link to see other GetDefaultFolder indexes:
After accessing the All Public Folders, this script walks down to the folder that needs the "Show As Address Book" marked. It accesses the folder by navigating through the first folder under the All Public Folders by indexes. The NSObj instance is used to access any folder under the All Public Folders, i.e. if you needed to customize this script to access the second or third folder under the All Public Folders then you would use and index of (2) or (3).
The next Set statement is if you need to mark a folder under the, for a lack of a better term, secondary folder. So, in the above example the All Public Folders is accessed then the first main folder under All Public Folders is access then the first folder under the main folder is accessed.



comments powered by Disqus