I am using Outlook 2007 on XP. It appears that Application.Quit event does not act like a Destructor. Outlook seems to clear all objects before entry into the event so there is no way to gracefully shutdown the application. Furthermore, it clears objects in such a way that class module's Terminate event is not called. Is this really correct?
I've stripped a large VBA app into a small piece of test code that demonstrates the issue - you'll find it below.
If you run Process Explorer you will see that IE never shuts down because IE.quit needs to run. If you uncomment IE.quit in Application_Quit event Outlook will crash because the IE object is no longer there.
Furthermore, there is a MsgBox in the StoreManager Terminate event. This message box never shows up showing that the destructor never runs.
However, Outlook clears these objects, it does so before the Quit event and in a way that does not all the object's destructor.
Please tell me I am missing something...this seems too terrible to be true as it would mean there is no way to gracefully showdown a VBA app.
-----CODE START------
Public ie As Object
Private test As StoreManager
Public Sub Initialize_Handler()
Set ie = CreateObject("internetexplorer.application")
ie.Navigate "about:blank"
Do
DoEvents
Loop While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
ie.Visible = True
Set test = New StoreManager
End Sub
Private Sub Application_Quit()
' ie.Quit
Set ie = Nothing
Set test = Nothing
MsgBox "OK to end"
End Sub
Private Sub Application_Startup()
Initialize_Handler
Stop
End Sub
Public Function ProcessManualTasks()
'Initialize_Handler
'ie.Quit
'Set ie = Nothing
'Quit
End Function
------CODE END------