Can not save Normal.dot error 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 but does not on
another.

What could be the readson for this error and how to resolve it?

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

Javed

why do you want to save it manually, Word manages to save the changes in
Normal.dot itself. The thing is that its a Global Template and used by all
the instances at the same time and u cant save it with other instances of
word open. Either dont save it and the word will save it iteself when all
the instances are closed or u can set the Saved property of NormalTemplate
to false manually to make it sure that word saves the changes at the end.
i.e.

WordApplicationObject.NormalTemplate.Saved = false ;

hope it will help
regards
--
Javed hussain
Software Developer
GoNetBPO (Pvt.) Ltd.
UAN: +92-21-111-276-111
Tel: +92-21-4391340-7 Ext: 407
Cell: 0300-2659032 Fax:+92-21-4547129
(e-mail address removed)
www.GoNetBPO.com
 

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