S
Simon
Hi,
I use vba code to open a new doc from a Word template (dot) file , and set
some values to bookmarks, and save it to a new file. I tried to close the
template dot file at the end, but it does not work. See the code below. The
thing is, as I found out by debugging the document loop, the template file
(Print_temp.Dot) is not in the Documents collection. The file handle
~$int_temp.dot remains there until I manually close the newly created
Print_New.doc file.
Advice please. Thanks.
Simon
---------------
Dim objWord As Word.Application
Dim NewDoc As Word.Document
Dim aDoc As Document
Set objWord = New Word.Application
Set NewDoc = objWord.Documents.Add("C:\Print_Templates\" & "Print_temp.Dot")
(do bookmark inserts to NewDoc)
NewDoc.SaveAs "C:\Print_New.doc"
objWord.Visible = True
'close template, here is the problem - the dot file is not in the Documents
collection
For Each aDoc In objWord.Documents
If aDoc.FullName = "C:\Print_Templates\" & "Print_temp.Dot") Then
aDoc.Close
Exit For
End If
Next
---------------------------
I use vba code to open a new doc from a Word template (dot) file , and set
some values to bookmarks, and save it to a new file. I tried to close the
template dot file at the end, but it does not work. See the code below. The
thing is, as I found out by debugging the document loop, the template file
(Print_temp.Dot) is not in the Documents collection. The file handle
~$int_temp.dot remains there until I manually close the newly created
Print_New.doc file.
Advice please. Thanks.
Simon
---------------
Dim objWord As Word.Application
Dim NewDoc As Word.Document
Dim aDoc As Document
Set objWord = New Word.Application
Set NewDoc = objWord.Documents.Add("C:\Print_Templates\" & "Print_temp.Dot")
(do bookmark inserts to NewDoc)
NewDoc.SaveAs "C:\Print_New.doc"
objWord.Visible = True
'close template, here is the problem - the dot file is not in the Documents
collection
For Each aDoc In objWord.Documents
If aDoc.FullName = "C:\Print_Templates\" & "Print_temp.Dot") Then
aDoc.Close
Exit For
End If
Next
---------------------------