Can not save normal.dot error when automating Word with 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.

'---------------------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
 

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