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