Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word template

Status
Not open for further replies.

Davidprince

Programmer
Jul 1, 2003
52
AU
Ladies and Gentlemen,
Hereunder is some code to add a new word doc programmatically. Could someone please advise me how to add a template (in this case a letterhead which is at
C:\Documents and Settings\David\My Documents\Standard Documents\Carlton & Partners letterhead 05) instead of a new document:

Private Sub cmdModifyDocument_Click()
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document

wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Add

With wrdDoc"
.Range.InsertBefore "Hello there everyone!"
.SaveAs "C:\Greetings.doc"
End With

Set wrdApp = Nothing
End Sub
Thanks
David
 
You wanted this ?
.SaveAs "C:\Documents and Settings\David\My Documents\Standard Documents\Carlton & Partners letterhead 05\Greetings.dot", wdFormatTemplate

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH, that would save the current doc as a template. I believe the request is for how to USE a template on the current doc. If I am correct in that (and I could of course be wrong), then you need to attach the template to the document.

The following assumes that the path you gave has a path separator before letterhead05, and that letterhead05 is, in fact, a .DOT file.

Also, I notice that while you do have wrdApp = Nothing, you do not have wrdApp.Quit. Using Quit is a good idea.
Code:
With wrdDoc.ActiveDocument
  .UpdateStylesOnOpen = False
  .AttachedTemplate = _
      "C:\Documents and Settings\David\My Documents\Standard Documents\Carlton & Partners\letterhead 05.dot"
  .Range.InsertBefore "Hello there everyone!" 
  .SaveAs "C:\Greetings.doc" 
End With

Gerry
 

Wouldn't it be simpler just to specify the template for the new document instead of changing it after opening?
Code:
    :
    :
    Set wrdDoc = wrdApp.Documents.Add _
                 "C:\Documents and Settings\David\My Documents\" & _
                 "Standard Documents\Carlton & Partners\letterhead 05.dot"

    With wrdDoc"
        .Range.InsertBefore "Hello there everyone!"
        .SaveAs "C:\Greetings.doc"
        .Close
    End With

    wrdApp.Quit
    Set wrdApp = Nothing
End Sub

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Gerry and Tony
Thanks guys, I like both solutions. I asked the question orinally because when I used the macro recorder I got a whole lot of ""s and I thought there was an easier way. So I thought Tek-Tips!
Regards
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top