Macro to Check for Multiple Instances of Word

Last reviewed: July 30, 1997
Article ID: Q109836
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Windows operating system versions 3.0 and 3.1

SYMPTOMS

You start Word when another instance of Word is already running, but you get no message to that effect.

CAUSE

In Microsoft Windows, if a share program such as SHARE.EXE, VSHARE.386, or any other share utility is in use, multiple instances of the same program can be run at the same time. You cannot configure Word to prevent this from occurring.

RESOLUTION

The follow macro, when named AUTOEXEC, will check to see if any other instances of Word are running and if so, will then give you the option of closing one instance or allowing a new instance.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  1. On the Tools menu, click Macro.

  2. In the Macro Name text box, type "AutoExec" (without the quotation marks).

  3. Be sure the Macros Available In list box displays NORMAL.DOT.

  4. Click the Create button.

  5. Type the following macro:

    Sub MAIN
         On Error Goto bye
         Dim ListBox1$(1)
         count = 0
         Text$ = "There is currently another instance of Word for Windows \
    
running . Please choose the instance you wish to Close Or choose Cancel \ to run both instances ."
     size = AppCount() - 1
     Dim winnames$(size)
     AppGetNames winnames$()
     For i = 0 To size
      If InStr(1, winnames$(i), "Microsoft Word") Then
       count = count + 1
       ListBox1$(count - 1) = winnames$(i)
      End If
      If count > 1 Then
       Begin Dialog UserDialog 322, 174, "Microsoft Word"
        OKButton 222, 121, 88, 21
        CancelButton 222, 147, 88, 21
        ListBox 10, 70, 300, 45, ListBox1$(), .ListBox1
        Text 10, 6, 300, 60, text$, .Text1
       End Dialog
       Dim dlg As UserDialog
       If Dialog(dlg) = - 1 Then
        AppClose(ListBox1$(dlg.ListBox1))
       End If
       i = size
      End If
     Next
bye:       '<-- This line MUST be left aligned
    End Sub

NOTE: In the macro above, the continuation character "\" is not necessary if the text is typed without a carriage return at the end of the line.

  1. On the File menu, click Save All, and click Yes when prompted to save changes to the AutoExec macro.

  2. Exit Word.

To test the macro, restart Word and then start a second instance of Word. You should receive a dialog box stating there are two instances of Word for Windows running. It will allow you to 1) choose one instance to close, or 2) choose Cancel to allow both applications to run simultaneously.

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: 6.0 6.0a 6.0c 7.0 word95 copies copy two
word7 word6 winword determine
Version : 6.0 6.0a 6.0c 7.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.