Creating a new document from a template

D

Dorian

From outside of MS Word (actually in MS Access), I need to create a new blank
word document based on a template and give the document a name.
Does anyone know how to do this?
I see I can use documents.add to create a new blank document based on a
template but how do I give the document a name? The name must be very
specific and I cannot rely on the user to type it in by doing a 'save' or
'save as'.
Thanks.
Here is my code so far:
Set objW = CreateObject("Word.Application")
objW.Visible = True
objW.ChangeFileOpenDirectory strPath
objW.Documents.Add "K:\Winword\TEMPLATE\OALSrules.dot", False,
wdNewBlankDocument, True
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
J

Jay Freedman

From outside of MS Word (actually in MS Access), I need to create a new blank
word document based on a template and give the document a name.
Does anyone know how to do this?
I see I can use documents.add to create a new blank document based on a
template but how do I give the document a name? The name must be very
specific and I cannot rely on the user to type it in by doing a 'save' or
'save as'.
Thanks.
Here is my code so far:
Set objW = CreateObject("Word.Application")
objW.Visible = True
objW.ChangeFileOpenDirectory strPath
objW.Documents.Add "K:\Winword\TEMPLATE\OALSrules.dot", False,
wdNewBlankDocument, True
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".

Word gives a document a name (other than the "DocumentN" assigned to unsaved
documents) only when the document is saved. However, the macro can save it
without waiting for the user. To facilitate this, declare a Document variable
and assign the result of the .Add to it; then you can call the document's
..SaveAs method to assign the name. Something like this:

Dim oDoc As Word.Document
Set objW = CreateObject("Word.Application")
objW.Visible = True
objW.ChangeFileOpenDirectory strPath
Set oDoc = objW.Documents.Add("K:\Winword\TEMPLATE\OALSrules.dot", _
False, wdNewBlankDocument, True)
oDoc.SaveAs FileName:=strPath & "\SpecificName.doc"

Note that when you use the result of the .Add method (that is, you're using it
as a function), the parentheses around the parameter list are required.

The .SaveAs method has a lot of other parameters, but they're all optional. Read
the help topic to see whether you want to use any of them.
 

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