Attach template to existing document; letterhead

R

robert.waters

I have a document template containing my company's letterhead; in our
semi-automated system, we typically use this template for new Word
documents that require it to appear:
Dim w As word.Application
Set w = New word.Application
w.Documents.Add ("<letterhead template path>")
w.ActiveDocument.SaveAs ("newdoc.doc")
' do stuff

However, I am tasked with including the letterhead in pre-existing
documents that lack it. I have tried attaching the template to the
existing documents, using 'ActiveDocument.AttachedTemplate', which
true to it's name attaches the template to the document, but does not
insert the letterhead.

Does anyone know how I might go about programmatically inserting
letterhead, using a .dot template, into a pre-existing document? If
not, is there another method (perhaps using autotext entries)?

Thank you in advance.
 
R

Russ

You may have come up with your own answer, create an autotext of what you
need and insert that into the other documents.

Here are is text from Word VBA help, I'm sure that there is more info to
search for in VBA Help on autotext.
AutoTextEntries Property Example
This example deletes the AutoText entry named "Hello" if the entry exists in
the attached template.
For Each entry In ActiveDocument.AttachedTemplate.AutoTextEntries
If entry.Name = "Hello" Then entry.Delete
Next entry
This example adds an AutoText entry named "Temp" to the Normal template. The
contents of the AutoText entry (the first word in the document) are then
displayed in a message box.
Set myEntry = NormalTemplate.AutoTextEntries.Add(Name:="Temp", _
Range:=ActiveDocument.Words(1))
MsgBox myEntry.Value
This example stores the contents of the selection as an AutoText entry named
"Address" in the attached template.
If Len(Selection.Text) > 1 Then
ActiveDocument.AttachedTemplate.AutoTextEntries.Add _
Range:=Selection.Range, Name:="Address"
End If
 
R

Russ

In your template you could add a button or menu item that would insert
autotext (letterhead), if it wasn't already there.
 

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