Unlisted Unlisted
New Member
- Outlook version
- Outlook 2016 64 bit
- Email Account
- Office 365 Exchange
I have VBA running that will automatically trigger a specific action (such as a message box) if one switches to the "mail" module by clicking the envelope icon on the lower left-hand corner of Outlook. I've pasted my code below and it works fine when I initially open a single Outlook window.
However, if I right click anywhere in Outlook that provides the "open in new window" context menu item and click it to open a new window, switching to the mail module does not generate the event in the new window ( it still works in the original Outlook window). My guess is that the Application.ActiveExplorer.NavigationPane that I reference initially works only with the original Outlook window. I'm not sure how to make it reference any new window as well and welcome thoughts from the folks on the forum.
Here is the code I have that works on the single Outlook window:
'This variable and the Application_Startup and Objpane_moduleswitch functions ensure that when you switch to the mail module, the unifiedinbox function is called
Dim WithEvents objPane As NavigationPane
' Get the NavigationPane object for the currently displayed Explorer object.
Private Sub Application_Startup()
Set objPane = Application.ActiveExplorer.NavigationPane
End Sub
' Check if the currently selected navigation module has changed to mail and if so run unified inbox sub.
Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule)
'Dim objModule As CalendarModule
If CurrentModule.NavigationModuleType = olModuleMail Then
MsgBox "Switched to mail module"
End If
End Sub
However, if I right click anywhere in Outlook that provides the "open in new window" context menu item and click it to open a new window, switching to the mail module does not generate the event in the new window ( it still works in the original Outlook window). My guess is that the Application.ActiveExplorer.NavigationPane that I reference initially works only with the original Outlook window. I'm not sure how to make it reference any new window as well and welcome thoughts from the folks on the forum.
Here is the code I have that works on the single Outlook window:
'This variable and the Application_Startup and Objpane_moduleswitch functions ensure that when you switch to the mail module, the unifiedinbox function is called
Dim WithEvents objPane As NavigationPane
' Get the NavigationPane object for the currently displayed Explorer object.
Private Sub Application_Startup()
Set objPane = Application.ActiveExplorer.NavigationPane
End Sub
' Check if the currently selected navigation module has changed to mail and if so run unified inbox sub.
Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule)
'Dim objModule As CalendarModule
If CurrentModule.NavigationModuleType = olModuleMail Then
MsgBox "Switched to mail module"
End If
End Sub