Using VbScript to create a new document from a template

M

Marceepoo

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
 
J

Jonathan West

Marceepoo said:
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

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)
 

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