How to check whether Word is open

Article contributed by Lutz Gentkow

Some users are very talented at opening many instances of Word, by repeatedly clicking on the shortcut, until memory or resources run out. This is particularly so with Word 97, where clicking on Word's shortcut almost always starts a new instance of Word. With Word 2000, clicking on Word's shortcut generally creates a new document using an existing instance of Word, if there is one; but if a Word dialog box is active at the time, even Word 2000 creates a new instance of Word.

So I have written the following macro to prevent users from doing this. Being an AutoExec macro, it fires automatically when you start a new instance of Word; and if it finds two open instances (the new one plus another one that was already open), then it activates the one that was already open and quits the new instance.

Sub AutoExec()

Dim Hits As Long, oTask As Task

  For Each oTask In Tasks
      If Left(oTask.Name, 14) = "Microsoft Word" Then Hits = Hits + 1
      If Hits = 2 Then
          oTask.WindowState = wdWindowStateMaximize
      End If
  Next oTask

End Sub

However, if you are using Automation to open Word from another application (such as a VB application, or Excel) and want to check whether Word is already open before you start, then you can't use the Tasks collection. Instead, use the method described in the article: Control Word from Excel.