When you automate multiple instances of Microsoft Word simultaneously, the user may receive one or more of the following warnings:
"Normal.dot 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\...\Normal.dot)
These warnings may occur if changes are made to the Normal.dot 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 Normal.dot template to True as follows:
Application.NormalTemplate.Saved = True
- Set the SaveChanges argument for the Quit method as follows:
Steps to Reproduce Behavior
- In Visual Basic, create a new Standard EXE project. Form1 is created by default.
- On the Project menu, click References, and then add a reference to your version of the Microsoft Word Object Library.
- Add a CommandButton control to Form1.
- 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."
Set wdApp2 = Nothing
Set wdApp1 = Nothing
- Run the Visual Basic project and click the command button.
- 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:
Article ID: 285885 - Last Review: January 29, 2007 - Revision: 5.2
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Office Word 2003
- Microsoft Word 2002
- Microsoft Word 2000
|kbautomation kbprb KB285885|