Outlook VSTO - Get all items in a group calendar

I am looking for a way to access a group calendar in Outlook VSTO Add-In. I am only able to search the default calendar in outlook. I have shared an image from outlook below that shows several group calendars. How can I access those group calendars from VSTO code?

Outlook group calendar navigation pane

2 answers

  • answered 2022-05-07 19:11 Eugene Astafiev

    You can use the NavigtionModule object in Outlook to get access to group calendars (or shared ones). The NavigationModule object provides access to the various navigation modules that are displayed in the Microsoft Outlook Navigation Pane. For example:

    Sub Test()
    Const olFolderCalendar = 9
    Const olModuleCalendar = 1
    Const olAppointmentItem = 1
    Dim answer As Integer
    Dim objNS
    Dim objExpCal
    Dim objNavMod
    Dim objNavGroup
    Dim objNavFolder
    Dim objFolder
    Dim colExpl
    Set oApp = CreateObject("Outlook.Application")
    Set objNS = oApp.Session
    Set colExpl = oApp.Explorers
    Set objExpCal = objNS.GetDefaultFolder(olFolderCalendar).GetExplorer
    Set objNavMod = objExpCal.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
    For Each objNavGroup In objNavMod.NavigationGroups
        For Each objNavFolder In objNavGroup.NavigationFolders
            If Not objNavFolder = "YOUR CALENDAR NAME" Then 'exactly as in Outlook
                GoTo NxtGroup
            End If
            On Error Resume Next
            Set objFolder = objNavFolder.Folder
    MsgBox objFolder.Name
    Set objNS = Nothing
    Set objNavMod = Nothing
    Set objNavGroup = Nothing
    Set objNavFolder = Nothing
    Set objFolder = Nothing
    Set colExpl = Nothing
    End Sub

  • answered 2022-05-08 03:36 Ashish Dhandharia

    Adding the C# version of the answer since the original question was requested for C#

            Outlook.NameSpace mapiNamespace = Globals.ThisAddIn.Application.GetNamespace("MAPI");
            Outlook.CalendarModule calendarModule = (Outlook.CalendarModule)mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).GetExplorer().NavigationPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar);
            Outlook.NavigationGroups navGroups = calendarModule.NavigationGroups;
            foreach (Outlook.NavigationGroup navGroup in navGroups)
                Outlook.NavigationFolders navFolders = navGroup.NavigationFolders;
                foreach (Outlook.NavigationFolder navFolder in navGroup.NavigationFolders)
                        if (navFolder.Folder != null && navFolder.Folder.Name.Equals("<Add your group calendar name here>"))
                           //do stuff here
                    catch (Exception ex)
                       //handle exception as needed and iterate to next 

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum