K
KK
Hello,
I am creating a vb application to use a word template, make a quick text
change and then save as a word document.
However, the following code worked on the initial run without any error. I
used this code in a simple vb form button click.
Templates("c:\test.dot").OpenAsDocument
Selection.Range.Text = "Made a change"
ActiveDocument.SaveAs "c:\test.doc"
ActiveDocument.Close saveChanges:=wdDoNoSaveChanges
But then afterwards it gives a warning of a run-time error '5941': The
requested member of the collection does not exist. This is referring to the
line
Templates("c:\test.dot").OpenAsDocument
however, this word template already exists in this location.
It only works now if you open the word template and leave it open in word
whilst you run the vb application.
Can anyone help explain why that error message comes up and how i can
prevent that happening. I am trying to get the vb application to utilise
the template without any error and create a word document in a designated
file location. This is without the need to keep that template in word open
explicitly.
Thanks.
Wing
I am creating a vb application to use a word template, make a quick text
change and then save as a word document.
However, the following code worked on the initial run without any error. I
used this code in a simple vb form button click.
Templates("c:\test.dot").OpenAsDocument
Selection.Range.Text = "Made a change"
ActiveDocument.SaveAs "c:\test.doc"
ActiveDocument.Close saveChanges:=wdDoNoSaveChanges
But then afterwards it gives a warning of a run-time error '5941': The
requested member of the collection does not exist. This is referring to the
line
Templates("c:\test.dot").OpenAsDocument
however, this word template already exists in this location.
It only works now if you open the word template and leave it open in word
whilst you run the vb application.
Can anyone help explain why that error message comes up and how i can
prevent that happening. I am trying to get the vb application to utilise
the template without any error and create a word document in a designated
file location. This is without the need to keep that template in word open
explicitly.
Thanks.
Wing