在导航窗格中将模块设置为“当前所选模块”

使用 Microsoft Outlook 中 NavigationPane 对象的 CurrentModule 属性将 NavigationModule 对象设置为 Explorer 对象的导航窗格中当前选定的导航模块。

如果以编程方式或通过用户操作在导航窗格中选定了“日记”导航模块,下面的示例会将“日历”导航模块设置为当前选定的导航模块。 本示例执行下列操作:

  1. 当引发 Application 对象的 Startup 事件并将其分配给 objPane时,该示例首先获取对活动资源管理器的 NavigationPane 对象的引用,以便可以检测到 NavigationPane 对象的 ModuleSwitch 事件。

  2. NavigationPaneModuleSwitch 事件发生时,该示例随后通过将 ModuleSwitch 事件的 CurrentModule 参数的内容与 NavigationPane 对象的 CurrentModule 属性进行比较来检查当前导航模块是否已更改。

  3. 如果这些对象引用不同,示例随后会在 ModuleSwitch 事件的 CurrentModule 参数中检查 NavigationModule 对象引用的 NavigationModuleType 属性。

  4. 如果当前选定 Module 对象的 NavigationModuleType 属性设置为 olModuleJournal ,示例将显示一个对话框来通知用户当前选定的 "日记" 导航模块暂时不可用,而改为选择 "日历" 导航模块。

  5. 最后,此示例使用 NavigationPane 对象的 Modules 集合的 GetNavigationModule 方法尝试检索 CalendarModule 对象。 如果成功,NavigationPane 对象的 CurrentModule 属性将设置为检索到的 CalendarModule 对象引用。

Dim WithEvents objPane As NavigationPane 
 
Private Sub Application_Startup() 
 ' Get the NavigationPane object for the 
 ' currently displayed Explorer object. 
 Set objPane = Application.ActiveExplorer.NavigationPane 
 
End Sub 
 
Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule) 
 Dim objModule As CalendarModule 
 
 ' Check if the currently selected navigation module 
 ' has changed. 
 If Not (CurrentModule Is objPane.CurrentModule) Then 
 ' If the Journal module was selected, forcibly change 
 ' it to the Calendar module by setting the 
 ' CurrentModule property of the NavigationPane object. 
 If CurrentModule.NavigationModuleType = olModuleJournal Then 
 
 ' Let the user know what's happening. 
 MsgBox "The Journal module is temporarily unavailable. " & _ 
 " Outlook is switching to the Calendar module, if available." 
 
 ' Retrieve the Calendar module, if one exists, for the 
 ' current Navigation Pane. 
 Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) 
 
 ' If we have one, set the CurrentModule property of the 
 ' NavigationPane object to the Calendar module. 
 If Not (objModule Is Nothing) Then 
 Set objPane.CurrentModule = objModule 
 End If 
 End If 
 End If 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。