Catching ModuleSwitch events after "open in new window"

Not open for further replies.

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
This is a question for @Michael Bauer. My logic says it should work, because the new window is the currently active activeexplorer, but it's probably also doing something with the window's index # and I have no idea how to work around it.
ActiveExplorer always points to the active explorer. However, if a new explorer is opened, it´s a new reference while the one stored in your variable still points to the first object.

You need to keep a ref on each opened explorer, which requires to add a class module to your project. This sample shows how to do that for inspectors:
Inspector Wrapper: Receive Events of Multiple Emails - VBOffice
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
oliv- Best practice for catching Outlook VBA and Custom Forms 0
Fozzie Bear Calendar Events created on iPhone have suddenly start sending invitations to attendees Using Outlook 2
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using accounts in Outlook 0
O After filtering, how to display all events on that day? Using Outlook 4
O Carriage Return - Line Feeds - exporting Calendar events Using Outlook 0
A Outlook Reminders not populating for certain events Using Outlook 2
J Outlook 2010 Changing events in Outlook calendar via opening file, importing CSV Using Outlook 0
P OWA Settings->Calendar->Events from Email; Setting changes do not hold Using Outlook 1
J Outlook Office 365 Win 10 how do I control background colors of events? Using Outlook 1
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
N Using email notification to update calendar events? Outlook VBA and Custom Forms 4
P Outlook custom fields "events" Using Outlook 0
T Categorizing different colors for a series of events Using Outlook 0
P Outlook 2013 Calendar events not appear on Calendar Using accounts in Outlook 6
V iCloud not syncing categorized calendar events Using Outlook 7
W All Events Disappear from Calendar Display Using Outlook 30
I Multiple events in single request Using Outlook 6
T Events Not Showing In Outlook Today Using Outlook 3
J Calendar view for future events only? Using Outlook 3
G Hiding All Day Events Using Outlook 1
microsvc Populating everyone's calendar with campus events Exchange Server Administration 1
Dave Godbey Sending Categories on Calendar Events Using Outlook 1
C Problem accessing events for folder "username" Server Threw Exception Using Outlook 1
S Syncing Past events from Outlook 2013 to Using accounts in Outlook 6
R How to turn OFF the Reminders for shared calendar events but not off personal Using Outlook 1
F Printing all day events only Using Outlook 3
E Outlook 2013 , iCloud linked calendar, events one hour ahead for about a month Using Outlook 5
B Timed events created in iPhone auto-change to All Day events in Outlook 2010 Using Outlook 2
H Events in Calendar not Bold Using Outlook 1
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
S Outlook - Reset the number of day-events Using Outlook 0
B Series of calendar events? Or Tasks? Using Outlook 1
D All New Appointments are All Day Events Using Outlook 1
P Printing calendar (work week) with numerous (i.e. >7) all day events... Using Outlook 3
A Outlook CPAO - Printing Monthly calendar with only all day events or catergory Using Outlook 2
S Full-day events Using Outlook 1
T Changing default reminder time for all day events - additional help needed Using Outlook 1
A Share recurrent events with others Using Outlook 2
O pasting text in body of calendar events Using Outlook 5
S Copy Events to Second Calendar or Sync Only "Busy" Events Using Outlook 5
K Private Calendar events Using Outlook 3
N How can i hsve appointments and events to not display start or finish times Using Outlook 2
T Birthday events in Calendar Using Outlook 4
G How to insert a json array into a calendar events Outlook VBA and Custom Forms 1
S Catch events from pre-existing buttons in Outlook 2007 Outlook VBA and Custom Forms 7
A how to capture events for next item Outlook VBA and Custom Forms 10
K Unable to receive events from Office::msoControlButton Outlook VBA and Custom Forms 3
M Outlook 2003 Plugin not receiving resize events Outlook VBA and Custom Forms 1
J Get Dates of Recurring Events in Shared Appointment Calendar Outlook VBA and Custom Forms 4

Similar threads