Prompt to save when using Word as an automation server

This article was previously published under Q285885
This article has been archived. It is offered "as is" and will no longer be updated.
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					

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    wdApp1.Documents.Add        Set wdApp2 = CreateObject("Word.Application")    wdApp2.Visible = True    wdApp2.Documents.Add                    MsgBox "Change the default font of document 2."        wdApp2.ActiveDocument.Close False    wdApp2.Quit    Set wdApp2 = Nothing    wdApp1.Quit    Set wdApp1 = NothingEnd 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: 12/05/2015 23:59:26 - Revision: 5.2

Microsoft Visual Basic 6.0 Professional Edition, Microsoft Office Word 2003, Microsoft Word 2002, Microsoft Word 2000

  • kbnosurvey kbarchive kbautomation kbprb KB285885