Outlook VBA - programatically add public folder as outlook address book

I would like to programatically add a public folder to the current logged in user's outlook address book (check to confirm it's not already in the outlook address book then add it if it's not).
Seems simple enough but I have been unable to find any such examples.  I can use any programming language required, I just need a solution that can run unattended.
LVL 27
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

David LeeConnect With a Mentor Commented:
Hi, ddrudik.

Do you mean you want to determine if "Show this folder as an e-mail address book" is checked and check it if it isn't?  If so, then something like this will get the job done.
Sub AddAddressBook(strFolderName As String)
    Const olPublicFoldersAllPublicFolders = 18
    Dim olkApp As Object, _
        olkNS As Object, _
        olkFolder As Object
    Set olkApp = CreateObject("Outlook.Application")
    Set olkNS = olkApp.GetNamespace("MAPI")
    Set olkFolder = olkNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders(strFolderName)
    If Not olkFolder.ShowAsOutlookAB Then
        olkFolder.ShowAsOutlookAB = True
    End If
    Set olkFolder = Nothing
    Set olkNS = Nothing
    Set olkApp = Nothing
End Sub

Open in new window

ddrudikAuthor Commented:
BlueDevilFan, thanks for the quick answer.
David LeeCommented:
You're welcome.  Glad I could help.
All Courses

From novice to tech pro — start learning today.