How to: Enumerate Active Folders in the Calendar View

In Microsoft Outlook, you can traverse the group and folder hierarchy of a module in the Navigation Pane by using the NavigationGroups and NavigationFolders collections. The NavigationGroups collection of the NavigationModule object contains each navigation group displayed in a navigation module, while the NavigationFolders collection of the NavigationGroup object contains each navigation folder displayed in a navigation group.

By using these collections in combination, you can enumerate each navigation folder for a navigation module displayed in the Navigation Pane.

The following sample counts the number of navigation folders selected for display in the Calendar navigation module of the Navigation Pane. The sample performs the following actions:

  1. The sample first obtains a reference to the NavigationPane object for the active explorer.

  2. It then uses the GetNavigationModule method of the NavigationModules collection to obtain a reference to the CalendarModule object from the NavigationPane object.

  3. The sample then enumerates through the NavigationGroups collection of the CalendarModule object. For each NavigationGroup in the collection, the sample then enumerates the NavigationFolders collection.

  4. If the IsSelected property of a NavigationFolder object contained in the NavigationFolders collection is set to True, the variable intCounter is incremented.

  5. Finally, the sample displays a dialog box containing the value of intCounter.

Dim WithEvents objPane As NavigationPane 
 
Private Sub EnumerateActiveCalendarFolders() 
 Dim objModule As CalendarModule 
 Dim objGroup As NavigationGroup 
 Dim objFolder As NavigationFolder 
 Dim intCounter As Integer 
 
 On Error GoTo ErrRoutine 
 
 ' Get the NavigationPane object for the 
 ' currently displayed Explorer object. 
 Set objPane = Application.ActiveExplorer.NavigationPane 
 
 ' Get the CalendarModule object, if one exists, 
 ' for the current Navigation Pane. 
 Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) 
 
 ' Iterate through each NavigationGroup contained 
 ' by the CalendarModule. 
 For Each objGroup In objModule.NavigationGroups 
 ' Iterate through each NavigationFolder contained 
 ' by the NavigationGroup. 
 For Each objFolder In objGroup.NavigationFolders 
 ' Check if the folder is selected. 
 If objFolder.IsSelected Then 
 intCounter = intCounter + 1 
 End If 
 Next 
 Next 
 
 ' Display the results. 
 MsgBox "There are " & intCounter & " selected calendars in the Calendar module." 
 
EndRoutine: 
 On Error GoTo 0 
 Set objFolder = Nothing 
 Set objGroup = Nothing 
 Set objModule = Nothing 
 Set objPane = Nothing 
 intCounter = 0 
 Exit Sub 
 
ErrRoutine: 
 MsgBox Err.Number & " - " & Err.Description, _ 
 vbOKOnly Or vbCritical, _ 
 "EnumerateActiveCalendarFolders" 
End Sub 

Show:
© 2015 Microsoft