Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

Using VbScript to create a new document from a template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marceepoo - 06 Aug 2007 06:08 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.