Larry,
What I've done in my letterhead is code that checks to see if the attached
template is the original "base" template. If it is not, it updates the
contents of the attached template copying styles as well as header/footers
from the base template to the new document. The base template has a document
variable with the name of that template. Other templates are created from
the base using SaveAs so they have the same document variable with the name
of the original template. So will documents created based on the derivative
templates. This allows for multiple base template sets.
The first part of it follows.
Dim sTemplateName As String
sTemplateName = ActiveDocument.Variables("BaseName").Value
' If this is not the base template for the letterhead, attach base
template
If ActiveDocument.AttachedTemplate.Name <> sTemplateName Then
ReplaceHeaders (sTemplateName) ' calls private sub (below)
' Application.OrganizerCopy( ' (for future work to update letterhead
styles)
AttachBase (sTemplateName)
End If
It is not necessary to attach the base to the new document, I just found
that to be a convenient way to update the styles. I don't do it in templates
that have customizations of their own beyond the text they contain.
Additional code follows:
Function WorkGroupPath() As String
' Written by Charles Kenyon
' February 28, 2003
'
' Used by templates menus to set location of templates.
' Returns workgroup tempates path with "\" at the end.
'
' This is needed because if the folder is a network drive rather
' than a folder, it will have the "\" already. If it is a folder,
' it will not have the backslash. This function gives a string
' with the backslash in either case.
'
WorkGroupPath =
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
If Right(WorkGroupPath, 1) <> "\" Then
WorkGroupPath = WorkGroupPath & "\"
End If
End Function
Private Sub AttachBase(sTemplateName As String)
' Procedure written by Charles Kyle Kenyon 8 Dec 2003
' Reattaches Base Letterhead Template for form letters - attaches styles
'
Dim sTemplatesPath As String
sTemplatesPath = WorkGroupPath & "Letters & Faxes\"
'
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = sTemplatesPath & sTemplateName
.UpdateStylesOnOpen = False
.AttachedTemplate = sTemplatesPath & sTemplateName
End With
End Sub
Private Sub ReplaceHeaders(sTemplateName As String)
' Replaces Header and FirstPageHeader with contents from
' base template
' Replaces Footer and FirstPageFooter with contents from
' base template
' Assumes that bookmarks have been preserved in base and copies.
' Otherwise will generate error
' Required bookmarks are "Footer1," "Footer2," "Header1," and
"Header2"
'
Dim rRange As Range
Dim sFooter As String
Dim sHeader As String
Dim iCount As Integer
'
' For iCount = 1 To 1 ' Replace 1st page header/footer only
For iCount = 1 To 2 ' Replace both headers, letterhead & continuation
sFooter = "Footer" & iCount
sHeader = "Header" & iCount
Set rRange = ActiveDocument.Bookmarks(sHeader).Range
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:=sHeader, _
ConfirmConversions:=False, Attachment:=False, Link:=False
Set rRange = ActiveDocument.Bookmarks(sFooter).Range
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:=sFooter, _
ConfirmConversions:=False, Attachment:=False, Link:=False
Next iCount
End Sub
This way I generally only have to make changes to either the document's
styles or adding macros / toolbars or keyboard customizations to the base
template. If you use the organizerCopy method, be sure you copy styles three
times (Copy all desired styles once, then again, then again) to make sure
that links between styles are maintained. Hope this gives you a start.
--
Charles Kenyon
See the MVP FAQ: <URL:
http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.