explorer_close not fired



Hi all
I'm a beginner in VBA outlook programming, so please be patient with me..

I am trying to run some code when outlook closes. My code need to access
some outlook inferface objects (menubar, buttons etc).
As far as I understand, if I put the code in the application_quit sub I
obtain an error, as my object variables are out of scope. So, I declared an
explorer object and I am trying to handle it with the explorer_close sub.
But the explorer.close event is not fired: why? It seems to me that the
myExplorer object is already set to nothing, and so the event cannot be
fired? I suppose so because if I open another explorer window and then close
the first one, the messagebox function DOES work!

Here's the code, all from the ThisOutlookSession module:

Dim WithEvents myExplorer As Outlook.Explorer

Private Sub Application_Quit()
Set myExplorer = Nothing
End Sub

Private Sub Application_Startup()
Set myExplorer = Application.Explorers.Item(1)
End Sub

Private Sub myExplorer_Close()
MsgBox "Closing..."
End Sub

If I open and then close outlook, nothing happens
If I open outlook, right-click a folder and choose "open in another window"
and then close the first outlook window, then the message "Closing..." pops
up, and the first outlook window closes.

Please help me, any suggestion would be really appreciated
Thank you so much

---Outlook 2003, XP PRO SP3---

Sue Mosher [MVP]

What is it that you need to do in Explorer_Close? There may be better ways
to accomplish your actual goals.


Hi Sue, thanks for your reply
I would need to execute a menu command: my final goal would be to
automatically delete IMAP messages marked for deletion when outlook closes.

Here's the actual code I tried to put in explorer_close (for better reading,
in my first post I replaced it with the msgbox):

Dim myBars As CommandBars
Dim myMenuBar As CommandBar
Dim myEditMenu As CommandBarControl

Set myBars = myExplorer.CommandBars
Set myMenuBar = myBars(4)
Set myEditMenu = myMenuBar.Controls(2)

If myEditMenu.Controls(11).Caption = "Rimuo&vi messaggi eliminati" Then
'"remove items marked for deletion"
MsgBox "mA cHE sTRANO!!" ' Error message (the menu is not the one I
intended to use)
End If

Set myBars = Nothing
Set myMenuBar = Nothing
Set myEditMenu = Nothing

Thank you very much for your help!


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question