Working with Explorer.Close event

Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
I'm trying to get Outlook to do some things when the user closes the application.

I tried using the app.quit event, but that's too late, because by the time it fires, Outlook has already released all of my variables/objects. I need to run my code in an event that fires before that.

I found some (sparse) documentation suggesting to use Explorer.Close() event for that reason. But I don't think the event is firing... or I've set it up wrong?

I declared global variables:
Private WithEvents MyExplorers as Outlook.Explorers
Private WithEvents MyExplorer as Outlook.Explorer.

In Application_Startup, I do:
Set MyExplorers = Application.Explorers
Set MyExplorer = MyExplorers.Item(1)
(And I've verified that it does get set)

Then I created:

Private Sub MyExplorer_Close()

>> This sub never runs. Why not?

(Further: I also created MyExplorers_NewExplorer() to verify that this event was firing. It does.)

I can find very little documentation or examples for the Explorer events.
Any help?

By the way -- the thing I'm ultimately trying to accomplish... While Outlook is running, I have a draft email that I use to log various stuff that I want logged. Before Outlook shuts down, I want it to Send that draft email to me. So have a global MyLog as MailItem, and I need to call MyLog.Send. That's what I want to put in MyExplorer.Close().
 
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
You can try to set RequireShutdownNotification in the registry for the VBA Addin, add that key to the Addin with a dword value of 1.
Thanks, Michael. What will that do? I'm guessing; but it doesn't sound like it will cause the Explorer.Close event to fire. Rather, it sounds like maybe it will cause Outlook to stop and wait for me to click a button before it closes?
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
It just notifies the Addin that Outlook is going to close.
 
Top