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
     Set wd = Nothing
     Set wd = GetObject(, "Word.Application")
     If Not wd Is Nothing Then
          wd.Quit 0 'wdDoNotSaveChanges
          Exit Do
     End If
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 (3)

  1. I’m confused — why do "I" need a script when Microsoft Office already provides the program "Microsoft Office Application Recovery" to close a hung program — or am I missing something?

  2. guowu says:

    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.

  3. Wordup says:

    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

Skip to main content