Microsoft KB Archive/266078

= BUG: Word 2000 Does Not Quit After Saving Hidden Document Using Automation =

Article ID: 266078

Article Last Modified on 11/4/2002

-

APPLIES TO


 * Microsoft Word 2000 Service Pack 1
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q266078



SYMPTOMS
When you are automating Microsoft Word 2000, the Quit method does not successfully shut down Word. Word is left in the task list even after your Automation client has called the Quit method. To quit Word, you must manually shut down the application by using the Windows Task Manager.



CAUSE
This problem occurs when:
 * The Automation client code is running in Debug mode (stepping through the code),

-and-
 * you call the Add or Open method of the Documents collection and specify False for the Visible argument to open a hidden document,

-and-
 * the hidden document is saved.



RESOLUTION
You can avoid this problem by using one of the following workarounds:
 * Programmatically open and close a blank document after saving the hidden document.

-or-
 * Open a blank document before calling the Quit method to quit Word.

-or-
 * Make the hidden document visible before calling the Quit method (requires Microsoft Word 2000 SR1 or SR1a).



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Word 2002.



Steps to Reproduce Behavior
 Start Visual Basic and create a new Standard EXE Project. Form1 is created by default. Place a CommandButton control on Form1. On the Project menu, select References, and then add a reference to the Microsoft Word 9.0 Object Library.  Paste the following code in the code window for Form1: Private Sub Command1_Click Dim oWord As Word.Application Dim oDoc As Word.Document

Stop Set oWord = CreateObject(&quot;Word.Application&quot;) oWord.Visible = True Set oDoc = oWord.Documents.Open(&quot;C:\test.doc&quot;, Visible:=False) oDoc.Save oWord.Quit Set oDoc = Nothing Set oWord = Nothing End Sub  Press the F5 key to run the project and click the CommandButton. Note that Visual Basic enters Debug mode at the Stop statement. Press F8 to step through the remaining lines of code. Note that after the Quit method, Word does not shut down but does report high CPU usage.</li></ol>

Workaround
To work around the problem in the preceding sample, you can do one of the following: <ul>  After you save the hidden document, open and close a blank document, as follows: oDoc.Save Dim temp as Word.Document Set temp = oWord.Documents.Add temp.Close Set temp = Nothing </li>  Before you quit Word, add a blank document: oWord.Documents.Add oWord.Quit </li>  Before you quit Word, unhide the hidden document: oDoc.ActiveWindow.Visible = True oWord.Quit To unhide the hidden document, you must have installed the Microsoft Office 2000 SR-1/SR-1a as explained in the following Microsoft Knowledge Base article:

220504 WD2000: Documents/Windows Collection Fails to Include Hidden Doc

If you do not have Microsoft Office 2000 SR-1/SR-1a installed, you receive a run-time error 91 when you attempt to unhide the document. </li></ul>

Additional query words: hang

Keywords: kbbug kbnofix kbprogramming kbautomation KB266078

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.