0

I am trying to read company conference room calendar events using MS Outlook 2013 VBA (MS Exchange).

My script works only with calendars I have permissions for writing, but the conference room shared calendars are read-only.

I get

Runtime error '-2147221233 (8004010f)'

Sub ShowOtherUserCalFolders()
    Dim namespace As Outlook.namespace
    Dim recipient As Outlook.recipient
    Dim CalendarFolder As Outlook.Folder
        
    Set namespace = Application.GetNamespace("MAPI")
    Set recipient = namespace.CreateRecipient("calendar-name")
    recipient.Resolve
    MsgBox recipient.Name
    'The name is shown correctly
        
    If recipient.Resolved Then
        Set CalendarFolder = namespace.GetSharedDefaultFolder(recipient, olFolderCalendar)
        'This should display the calendar on the screen, but it fails
        CalendarFolder.Display
        Dim oItems As Outlook.Items
        Set oItems = CalendarFolder.Items
        'The oItems is empty when trying to use read-only calendar
        MsgBox oItems.Count
    End If
End Sub
Community
  • 1
  • 1
  • Walk the folder tree from namespace to topfolder to subfolder to "calendar-name" https://stackoverflow.com/a/9077144 – niton Dec 14 '17 at 17:35

2 Answers2

0

You can walk the folder tree to the applicable folder.

Option Explicit

Sub ShowOtherUserCalFolders1()

    Dim CalendarFolder As Folder
    Dim oItems As items
    Dim currFolder_entryID As String

    ' Walk the folder tree to the applicable folder

    ' Right click on folder | Properties
    '  General Tab | Location
    '   \\Highest level name of shared Boardrooms\subfolder

    Set CalendarFolder = Session.folders("Highest level name of shared Boardrooms")
    Set CalendarFolder = CalendarFolder.folders("subfolder")
    Set CalendarFolder = CalendarFolder.folders("boardroom name")

    Set ActiveExplorer = CalendarFolder
    Set oItems = CalendarFolder.items
    MsgBox CalendarFolder & " has " & oItems.count & " items"

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52
0

You can reference the boardroom directly with entryID.

Option Explicit

Sub ShowOtherUserCalFolders2()

    Dim CalendarFolder As Folder
    Dim oItems As items
    Dim currFolder_entryID As String

    ' Reference the boardroom directly with entryID
    '  Open the applicable calendar

    ' In the immediate pane
    ' ?ActiveExplorer.CurrentFolder.EntryID
    ' or
    Debug.Print ActiveExplorer.CurrentFolder.EntryID

    ' Once you know the entryID, hardcode and uncomment
    'currFolder_entryID = "entryID shown in the immediate pane"

    'Set CalendarFolder = Session.GetFolderFromID(currFolder_entryID)

    'Set ActiveExplorer = CalendarFolder
    'Set oItems = CalendarFolder.items
    'MsgBox "" & CalendarFolder & " has " & oItems.count & " items"

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52