Prompt to save when using Word as an automation server


When you automate multiple instances of Microsoft Word simultaneously, the user may receive one or more of the following warnings:
" was being edited by another Word session. If you save this document with the original name, you will overwrite any changes made in the other session. Do you want to save the document using the original name anyway?"
This file is in use by another application or user. (C:\Documents and Settings\...\
These warnings may occur if changes are made to the template.


To resolve this problem, do one of the following:

  • Before you quit Word or transfer control to the user, set the Saved property of the template to True as follows:
    Application.NormalTemplate.Saved = True

  • Set the SaveChanges argument for the Quit method as follows:
    Application.Quit SaveChanges:=wdDoNotSaveChanges

More Information

Steps to Reproduce Behavior

  1. In Visual Basic, create a new Standard EXE project. Form1 is created by default.
  2. On the Project menu, click References, and then add a reference to your version of the Microsoft Word Object Library.
  3. Add a CommandButton control to Form1.
  4. Add the following code to the form:
    Private Sub Command1_Click()
    Dim wdApp1 As Word.Application
    Dim wdApp2 As Word.Application

    Set wdApp1 = CreateObject("Word.Application")
    wdApp1.Visible = True

    Set wdApp2 = CreateObject("Word.Application")
    wdApp2.Visible = True

    MsgBox "Change the default font of document 2."

    wdApp2.ActiveDocument.Close False
    Set wdApp2 = Nothing

    Set wdApp1 = Nothing
    End Sub
  5. Run the Visual Basic project and click the command button.
  6. A message box directs you to change the default font for the second document. On the Format menu, click Font, and then click Default. When you are prompted to change the default font, click Yes, and then click OK to dismiss the message box.
When the second Word instance is closed, one of the warnings shown in the "Summary" section appears.

To resolve this issue in the code above, do one of the following:

  • Add the following line before the call to the wdApp2.Quit method:
        wdApp2.NormalTemplate.Saved = True


  • Use the SaveChanges argument of the Quit method as follows:
        wdApp2.Quit SaveChanges:=wdDoNotSaveChanges

Article ID: 285885 - Last Review: Mar 23, 2009 - Revision: 1