Freigeben über


How to: Enumerate, Show, Hide, and Position Modules in the Navigation Pane

Outlook Developer Reference

The NavigationModules property of the NavigationPane object in Microsoft Office Outlook 2007 provides access to the navigation modules contained by the Navigation Pane. You can use the Item method to enumerate the NavigationModule objects contained by the collection, as the Item method is both the default property and the indexer property for the NavigationModules collection. The CurrentModule property determines which NavigationModule object is currently selected in the Navigation Pane.

Also, each NavigationModule object provides several properties that can be used to show, hide, or change the display position of modules in the Navigation Pane:

  • The Visible property determines whether a NavigationModule object can be displayed in the Navigation Pane.
  • The Position property determines the ordinal position of a NavigationModule object when displayed in the Navigation Pane.

The DisplayedModuleCount property of the NavigationPane object determines the number of visible NavigationModule objects that can be displayed by the Navigation Pane. If the Visible property of a NavigationModule object is set to False, or if the Position property of the NavigationModule object is set such that the module doesn't fall within the number of visible NavigationModule objects that can be displayed in the Navigation Pane, the module isn't displayed.

The following sample consists of three event handlers:

  • An event handler for the FolderContextMenuDisplay event of the Application object, which adds two new menu items named Move module to top and Show all modules to the bottom of the folder context menu, as a separate group.
  • An event handler for the Click event of the Move module to top menu item, which sets the currently selected module as the topmost displayed module in the Navigation Pane.
  • An event handler for the Click event of the Show all modules menu item, which makes all of the modules contained in the Navigation Pane visible and ensures that all modules are displayed by the Navigation Pane.

This sample performs the following actions:

  1. The FolderContextMenuDisplay event handler creates a new CommandBarButton object, objMoveButton, in the folder context menu. It then sets the BeginGroup property to True, to start a new group at the bottom of the context menu, and sets the Caption property to Move module to top.
  2. It then creates a new CommandBarButton object, objShowButton, in the folder context menu and sets the Caption property to Show all modules.
  3. If the Move module to top menu item is selected in the folder context menu, the Click event handler for objMoveButton uses the NavigationPane property of the Explorer object to retrieve a NavigationPane object.
  4. It then uses the CurrentModule property of the NavigationPane object to retrieve the currently selected NavigationModule object and sets the Position property of that NavigationModule object to 1, making it the topmost displayed module in the Navigation Pane.
  5. If the Show all modules menu item is selected in the folder context menu, the Click event handler for the CommandBarButton object objShowButton uses the NavigationPane property of the Explorer object to retrieve a NavigationPane object.
  6. It then enumerates the Modules collection of the NavigationPane object, setting the Visible property of each NavigationModule object contained in the collection to True.
  7. It finally sets the DisplayedModuleCount property of the NavigationPane object to the value of the Count property of the NavigationModules collection for the NavigationPane object, ensuring that every navigation module contained in the Navigation Pane is visible to the user.
  Dim WithEvents objPane As NavigationPane
Dim WithEvents objMoveButton As CommandBarButton
Dim WithEvents objShowButton As CommandBarButton

Private Sub Application_FolderContextMenuDisplay( _ ByVal CommandBar As Office.CommandBar, _ ByVal Folder As Folder)

' Add the objMoveButton menu item to the
' folder context menu.
Set objMoveButton = CommandBar.Controls.Add( _
    msoControlButton)
objMoveButton.BeginGroup = True
objMoveButton.Caption = "Move module to top"

' Add the objShowButton menu item to the
' folder context menu.
Set objShowButton = CommandBar.Controls.Add( _
    msoControlButton)
objShowButton.Caption = "Show all modules"

End Sub

Private Sub objMoveButton_Click( _ ByVal Ctrl As Office.CommandBarButton, _ CancelDefault As Boolean)

Dim objPane As NavigationPane

' Get the NavigationPane object for the
' currently displayed Explorer object.
Set objPane = Application.ActiveExplorer.NavigationPane

' Set the Position property of the currently selected
' module to 1, making it the topmost module displayed
' in the Navigation Pane.
objPane.CurrentModule.Position = 1

End Sub

Private Sub objShowButton_Click( _ ByVal Ctrl As Office.CommandBarButton, _ CancelDefault As Boolean)

Dim objPane As NavigationPane
Dim objModule As NavigationModule

' Get the NavigationPane object for the
' currently displayed Explorer object.
Set objPane = Application.ActiveExplorer.NavigationPane

' This loop enumerates through the Modules collection,
' setting the Visible property of each module to True.
For Each objModule In objPane.Modules
    objModule.Visible = True
Next

' Set the DisplayedModuleCount property to
' display all modules contained by the
' Navigation Pane.
objPane.DisplayedModuleCount = objPane.Modules.Count

End Sub