Share via


Handy-Dandy Scripts: closing Word gracefully

Sometimes you may find winword.exe process lingering in the memeory and there is no visible Word window that allows you to close it. Believe me, this mostly likely is not Word's fault: chances are that those ghost Word instances are started by some third party applications via automation. But for some reason those applications are not able to terminte the Word instances they brought up. 

 

Now aside from blaming third party applications, what can you do to close Word gracefully? You certainly could kill the process from task manager or other process managing applications. But that is not something called "gracefully": for one thing setting changes you made to Word may get lost. Second if the killed Word instance has modified document open, you will be greeted by the "Document Recovery" taskpane next time you starts Word.

 

In case you don't know, the trick is to use GetObject to connect to the existing Word Application COM object. Running a simple vbscript like the one below should do the job:

 

On Error Resume Next

Do

     Set wd = Nothing

     Set wd = GetObject(, "Word.Application")

     If Not wd Is Nothing Then

          wd.Quit 0 'wdDoNotSaveChanges

     Else

          Exit Do

     End If

Loop

 

Warning: the above script will force Word to quit without saving any changes. If you have unsaved but important changes pending in a "ghost" Word instance, you should use GetObject to connect to the instance first, then save your changes with Word object model.

Comments

  • Anonymous
    November 05, 2005
    The comment has been removed
  • Anonymous
    November 08, 2005
    Blake, you are 100% right. That application should be used for this very purpose. The script is quick and easy though if you have to do this a lot, e.g, testing your application driving Word automation. That is why I wrote the script for the first place.
  • Anonymous
    March 13, 2006
    Instances of the Winword process can be left running in background if Outlook is configured to use Word as it's default email editor.  This can be changed through the Mail Format tab in Outlooks options