Can not save normal.dot when automating Word from VBScript

  • Thread starter Viatcheslav V. Vassiliev
  • Start date
V

Viatcheslav V. Vassiliev

When the script below runs Word raises error "Word cannot save this file
because it is already open elsewhere. (C:\Documents and
Settings\...\Normal.dot)". This happens only when another document is
already open in Word before starting script. If Word is not open, script
runs OK. Any combination of word.NormalTemplate.Saved = true,
doc.Application.NormalTemplate.Saved = true, doc.AttarchedTemplate.Saved =
true does not help. The error happens on one computer and does not - on
another.
What could be a reason for this error and how to solve this?

'---------------------test.vbs-----------------
dim word, doc, rng
set word = CreateObject("Word.Application")
'word.DisplayAlerts = 0
word.Visible = true
set doc = word.Documents.Add
set rng = doc.Range(0, 0)
rng.InsertBefore("Some text")
rng.InsertParagraphAfter()
set rng = nothing
'doc.Application.NormalTemplate.Saved = true
'doc.AttachedTemplate.Saved = true
doc.SaveAs "C:\temp\vbs_test.doc"
'doc.Application.NormalTemplate.Saved = true
'doc.AttachedTemplate.Saved = true
set doc = nothing
word.NormalTemplate.Saved = true
word.Quit
set word = nothing
MsgBox "Done"
'---------------------test.vbs-----------------

Best regards,
Viatcheslav V. Vassiliev
 
P

Peter

It doesn't look like your script is doing anything to Normal.dot. On the computer on which this does not work, have you checked for any other global addins/templates that might be trying to save Normal.dot? The Adobe addin is notorious for doing that.
You can have it alert you when Normal.dot is being saved by going to Tools -> Options... -> Save tab and checking the "Prompt to save Normal template" checkbox. Then manually open a document and see if a prompt dialog pops up on close.
Also, check the Startup folder and Tools -> Templates and Add-ins for other templates/addins.

hth,

-Peter
 
V

Viatcheslav V. Vassiliev

Yes, computer that shows this message has some PDF stuff and shows dialog if
"Prompt to save Normal template" is checked.

Can I avoid addins when startin Word or avoid messages? word.DisplayAlerts =
0 works, it does not show "Do you want to save Normal.dot?" message, but
instead it shows "Can not save normal.dot" - for script automation I would
like to have no messages at all and do not save Normal.dot if it can not be
saved (really, I prefer to not save it in all cases).

Call to word.NormalTemplate.Saved = true just before word.Quit does not
help.

Is it possible to start Word from script without loading any addins?

Thank for your answer,
Viatcheslav V. Vassiliev

"Peter" <peterguy -at- hotmail -dot- com> ???????/???????? ? ????????
?????????: It doesn't look like your script is doing anything to Normal.dot. On the
computer on which this does not work, have you checked for any other global
addins/templates that might be trying to save Normal.dot? The Adobe addin
is notorious for doing that.
You can have it alert you when Normal.dot is being saved by going to
Tools -> Options... -> Save tab and checking the "Prompt to save Normal
template" checkbox. Then manually open a document and see if a prompt
dialog pops up on close.
Also, check the Startup folder and Tools -> Templates and Add-ins for other
templates/addins.

hth,

-Peter
 
P

Peter

Viatcheslav V. Vassiliev said:
Yes, computer that shows this message has some PDF stuff and shows dialog if
"Prompt to save Normal template" is checked.

Can I avoid addins when startin Word or avoid messages? word.DisplayAlerts =
0 works, it does not show "Do you want to save Normal.dot?" message, but
instead it shows "Can not save normal.dot" - for script automation I would
like to have no messages at all and do not save Normal.dot if it can not be
saved (really, I prefer to not save it in all cases).

Call to word.NormalTemplate.Saved = true just before word.Quit does not
help.

Is it possible to start Word from script without loading any addins?

Yes, but the only way I know how to do that is via the command line. You invoke word with the /a switch.
http://support.microsoft.com/kb/q210565/

I don't know how to do it via object instantiation. Perhaps you could shell Word, then use GetObject? I've heard bad things about using GetObject.

Anyone else have other ideas?

hth,

-Peter
 
V

Viatcheslav V. Vassiliev

GetObject is not an option because this error happens only when one instance
of Word is already open and script starts another instance. GetObject will
not allow to choose which instance use.

Thank you for help,
Viatcheslav V. Vassiliev

"Peter" <peterguy -at- hotmail -dot- com> ???????/???????? ? ????????
?????????:
Viatcheslav V. Vassiliev said:
Yes, computer that shows this message has some PDF stuff and shows dialog if
"Prompt to save Normal template" is checked.

Can I avoid addins when startin Word or avoid messages? word.DisplayAlerts =
0 works, it does not show "Do you want to save Normal.dot?" message, but
instead it shows "Can not save normal.dot" - for script automation I would
like to have no messages at all and do not save Normal.dot if it can not be
saved (really, I prefer to not save it in all cases).

Call to word.NormalTemplate.Saved = true just before word.Quit does not
help.

Is it possible to start Word from script without loading any addins?

Yes, but the only way I know how to do that is via the command line. You
invoke word with the /a switch.
http://support.microsoft.com/kb/q210565/

I don't know how to do it via object instantiation. Perhaps you could shell
Word, then use GetObject? I've heard bad things about using GetObject.

Anyone else have other ideas?

hth,

-Peter
 
P

Peter

Viatcheslav V. Vassiliev said:
GetObject is not an option because this error happens only when one instance
of Word is already open and script starts another instance. GetObject will
not allow to choose which instance use.

True.

You might try un-installing the addins:

for each add in word.AddIns
add.Installed = false
next

but then how to re-install them so the user doesn't muiss them?

-Peter
 
V

Viatcheslav V. Vassiliev

Peter, thank you for the help. Uninstall addins is not an option too, they
should be reinstalled before calling word.Quit().

Best regards,
Viatcheslav V. Vassiliev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top