Access non-default calendar in Outlook VBA

Hi Experts,

I'm trying to access the calendar of a shared mailbox through Outlook VBA. I see the calendar in My calendars , not Shared Calendars. The properties of that calendar read:
Type: Folder containing Calendar Items

TItle: Production Calendar
Location:\\Calendars\Calendar

There is a folder called calendar in
MyOlApplication.GetNamespace("MAPI").Folders("Calendars")

Open in new window

, but there are no folders within that folder, nor any appointment items (I tried to retrieve with the below loop).
    For Each oItem In MyOlNameSpace.Folders("Calendars").Folders("Calendar").Items
        If oItem.Class = olAppointmentItem Then
            Debug.Print oItem.Subject
        End If
    Next

Open in new window


Can you tell me where to find that dratted calendar?

Thanks,

Thomas
LVL 39
nutschAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

omgangIT ManagerCommented:
It's been a while but I had this code in my test/sample/dev stuff.  This is how you reference a shared calendar or calendar in a secondary mailbox.
OM Gang


Public Function OpenSharedCalendar()
On Error GoTo Err_OpenSharedCalendar
    Dim myOlApp As Outlook.Application
    Dim myNamespace As Outlook.NameSpace
    Dim myRecipient As Outlook.Recipient

    Dim fldr As Object
    Dim CalendarFolder As Object
    Dim Name As String
    Dim blResolve As Boolean
    
    Name = "some shared mailbox"

    Set myOlApp = CreateObject("Outlook.Application")
    Set myNamespace = myOlApp.GetNamespace("MAPI")
    Set myRecipient = myNamespace.CreateRecipient("=" & Name)

    blResolve = myRecipient.Resolve
    
    If myRecipient.Resolve Then
        Set CalendarFolder = Session.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
        Debug.Print CalendarFolder.Name
    Else
        MsgBox ("Could not resolve '" & Name & "' to obtain shared calendar")
        Set OpenSharedCalendar = Nothing
        Exit Function
    End If

Exit_OpenSharedCalendar:
    Set CalendarFolder = Nothing
    Set myRecipient = Nothing
    Set myNamespace = Nothing
    Set myOlApp = Nothing
    Exit Function

Err_OpenSharedCalendar:
    MsgBox Err.Number & ", " & Err.Description, , "Error in Function OpenSharedCalendar of VBA Document ThisOutlookSession"
    Resume Exit_OpenSharedCalendar
    
End Function

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
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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
Outlook

From novice to tech pro — start learning today.