none
Outlook list all Calendar Folders RRS feed

  • Question

  • hi gurus, how do I get the names of all available local calendar folders using VBA?

    If I have 5 calendars on my outlook store locally, how to programatically access the names of each calendar?

    Thanks for any input.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.


    • Edited by cguan Wednesday, February 26, 2014 6:12 AM edit
    Wednesday, February 26, 2014 4:19 AM

Answers

  • Hi,

    with this code

    Sub ListeCalendrierPartagé()
    '---------------------------------------------------------------------------------------
    ' Procedure : ListCalendar
    ' Author    : Oliv-
    ' Date      : 19/02/2014
    ' Purpose   : Liste les des "calendrier partagé" et le Dossier correpondant
    '---------------------------------------------------------------------------------------
    '
        Dim objNS As Outlook.NameSpace
        Dim objExpCal As Outlook.Explorer
        Dim objNavMod As Outlook.CalendarModule
        Dim objNavCalPart As Outlook.NavigationFolders
        Dim i, objitem
     
        Set objNS = Application.Session
        Set objExpCal = objNS.GetDefaultFolder(olFolderCalendar).GetExplorer
     
        Set objNavMod = objExpCal.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
        Set objNavCalPart = objNavMod.NavigationGroups.item("My Calendars").NavigationFolders
        For i = 1 To objNavCalPart.Count
            Set objitem = objNavCalPart(i)
            On Error Resume Next
     
            FoldName = objitem.Folder.Name & "-" & objitem.Folder.FullFolderPath
            If Err Then FoldName = "Pas accessible"
    Debug.Print objitem & "-->" & FoldName
     
        Next i
    End Sub


    Have a nice day. Oliv-

    • Marked as answer by cguan Friday, February 28, 2014 3:10 AM
    Wednesday, February 26, 2014 8:42 AM
  • Hello cguan,

    The Outlook object model provides the following methods for getting the calendar folder, you may find them useful:

    • NameSpace.GetSharedDefaultFolder - returns a Folder object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder).
    • NameSpace.GetDefaultFolder - returns a Folder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on.
    • Store.GetDefaultFolder - returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the  NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    Hope you will find them useful.


    • Edited by Eugene Astafiev Wednesday, February 26, 2014 3:39 PM
    • Marked as answer by cguan Friday, February 28, 2014 3:10 AM
    Wednesday, February 26, 2014 3:38 PM

All replies

  • Hi,

    with this code

    Sub ListeCalendrierPartagé()
    '---------------------------------------------------------------------------------------
    ' Procedure : ListCalendar
    ' Author    : Oliv-
    ' Date      : 19/02/2014
    ' Purpose   : Liste les des "calendrier partagé" et le Dossier correpondant
    '---------------------------------------------------------------------------------------
    '
        Dim objNS As Outlook.NameSpace
        Dim objExpCal As Outlook.Explorer
        Dim objNavMod As Outlook.CalendarModule
        Dim objNavCalPart As Outlook.NavigationFolders
        Dim i, objitem
     
        Set objNS = Application.Session
        Set objExpCal = objNS.GetDefaultFolder(olFolderCalendar).GetExplorer
     
        Set objNavMod = objExpCal.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
        Set objNavCalPart = objNavMod.NavigationGroups.item("My Calendars").NavigationFolders
        For i = 1 To objNavCalPart.Count
            Set objitem = objNavCalPart(i)
            On Error Resume Next
     
            FoldName = objitem.Folder.Name & "-" & objitem.Folder.FullFolderPath
            If Err Then FoldName = "Pas accessible"
    Debug.Print objitem & "-->" & FoldName
     
        Next i
    End Sub


    Have a nice day. Oliv-

    • Marked as answer by cguan Friday, February 28, 2014 3:10 AM
    Wednesday, February 26, 2014 8:42 AM
  • Hello cguan,

    The Outlook object model provides the following methods for getting the calendar folder, you may find them useful:

    • NameSpace.GetSharedDefaultFolder - returns a Folder object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder).
    • NameSpace.GetDefaultFolder - returns a Folder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on.
    • Store.GetDefaultFolder - returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the  NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    Hope you will find them useful.


    • Edited by Eugene Astafiev Wednesday, February 26, 2014 3:39 PM
    • Marked as answer by cguan Friday, February 28, 2014 3:10 AM
    Wednesday, February 26, 2014 3:38 PM
  • with namespace you need to search calendars in all the folders and subfolders.

    use this

    Public MyCalendars As New Collection
    
    
    Sub ListSubFolders()
    
        Dim OL As Outlook.Application
        Dim olNS As Outlook.NameSpace
        Dim OLFolder As Outlook.Folder
    
        Set OL = New Outlook.Application
        Set olNS = OL.GetNamespace("MAPI")
    
        Set OLFolder = olNS.GetDefaultFolder(olFolderInbox).Parent
        ProcessFolder OLFolder
        
        MsgBox "found " & MyCalendars.Count & " calendars"
        
    End Sub
    
    
    Sub ProcessFolder(StartFolder As Outlook.MAPIFolder)
        Dim objFolder As Outlook.MAPIFolder
        'Dim objItem As Object
        On Error Resume Next
    
        ' do something specific with this folder
    
        If StartFolder.DefaultItemType = olAppointmentItem Then
        Debug.Print StartFolder.FolderPath, StartFolder.Items.Count
        Debug.Print
        MyCalendars.add StartFolder
        End If
        ' process all the subfolders of this folder
        For Each objFolder In StartFolder.Folders
            Call ProcessFolder(objFolder)
        Next
    
        Set objFolder = Nothing
    End Sub
    


    Have a nice day. Oliv-

    Wednesday, February 26, 2014 9:28 PM
  • Thank you guys for your help.

    I'm just wondering why this never pop up on my search :

    GetNavigationModule(olModuleCalendar)

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Friday, February 28, 2014 3:11 AM