I'm trying to use vbscript to create a new document based on a template.
My code returns the following error message:
Object doesn't support this property or method:
'objWord.Application.Documents.OpenAsDocument'
Code: 800A01B6
Microsoft VBScript runtime error
Here's the code (that doesn't work):
'----------------------------------------------------------------
' Create a New Word Document
' http://msdn2.microsoft.com/en-us/library/aa200289(office.10).aspx
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
sLetterTemplate = "K:\Data\Programs\OfficeWorkGroup\Templates\Letter.dot"
Set objDoc = objWord.Application.Documents.OpenAsDocument(sLetterTemplate,
False, sLetterTemplate, Visible)
'----------------------------------------------------------------
Question: Does anybody have any suggestions about how I could create a new
document from the "Letter.dot" template?
Thanks,
marceepoo
Jonathan West - 06 Aug 2007 08:16 GMT
> I'm trying to use vbscript to create a new document based on a template.
> My code returns the following error message:
[quoted text clipped - 24 lines]
>
> marceepoo
The openAsDocument method applies to a Template object. A Template Object is
the attached template of a document that is already open. You need the Add
method of the Documents collection
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
sLetterTemplate = "K:\Data\Programs\OfficeWorkGroup\Templates\Letter.dot"
Set objDoc = objWord.Application.Documents.Add(sLetterTemplate)

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup