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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ddrudikAuthor Commented:
BlueDevilFan, thanks for the quick answer.
David LeeCommented:
You're welcome.  Glad I could help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.