Difference between Quit in Word and Excel
Posted on 2005-04-26
Please note that I have a very specific issue that I am trying to get clarification on. Please read this post in full before commenting.
My issue is that I have noticed that .Quit in MS Word (97 / XP) and .Quit in Excel (97 / XP) seem to have quite different behaviours. In particular, .Quit results in the Word process unloading from memory, while .Quit in Excel allows Excel to be unloaded from memory only if there are no references to objects within the Excel process.
My question (read further for more details) is to identify whether *MS has stated that the behaviour I am seeing is documented and reliable* (ie will always happen).
As an example, see the below VB 6 code:
Private app As Word.Application
Private Sub cmdRunWord_Click()
Dim doc As Word.Document
Set app = New Word.Application
Set doc = app.Documents.Add
doc.Application.Visible = True
Private app As Excel.Application
Private Sub cmdExcel_Click()
Dim wks As Excel.Workbook
Set app = New Excel.Application
Set wks = app.Workbooks.Add
wks.Application.Visible = True
Private Sub cmdSetToNothing_Click()
Set app = Nothing
Note that if you open your Task Manager (to see what processes are running), you can see when you run the Word code that WINWORD.EXE is no longer in memory, even though app has not been set to Nothing. But if you run the Excel code, EXCEL.EXE does not unload from memory until all objects are Nothing (ie until you click cmdSetToNothing).
The difference in behaviour is significant (I won't go into the details, but they are related to VB.NET / COM Interop) so I am looking for an *official MS statement* (a blog entry from a MS staffer would be fine) that the difference in behaviour between Word and Excel is by design and particularly that app.Quit can be relied upon to close the WINWORD.EXE process reliably.