Re: font changes in letterhead macro

From: Charles Kenyon (msnewsgroup_at_remove.no.spam.addbalance.com)
Date: 05/19/04

  • Next message: Jean-Guy Marcil: "Re: Replacing spaces with 1 space or a tab"
    Date: Wed, 19 May 2004 14:13:32 -0500
    
    

    First question that comes to mind is why use the macro rather than simply
    have it in the template's header to start with?

    Your problem probably involves the interaction of styles and direct
    formatting. This is probably different in your document than in the
    development environment. You may also have your styles set (problematically)
    to automatically update. If you do, switch this off on all styles normally
    used in your letters.

    While I use macros to insert letterhead content, I do it because I want to
    be able to change the content in one location and have it change in all form
    letters. At the same time the content is copied from the source, the styles
    are also copied.

    Also, recorded macros are lousy when dealing with headers/footers. They make
    the screen jump around a lot. Try using the range object instead. What
    follows is from my Letterhead module:

    Option Explicit
    ' Module written by Charles Kyle Kenyon on 08 Dec 2003
    ' Copyright 2003, 2004, Charles Kyle Kenyon, Madison, WI, USA, all rights
    reserved
    '

    Sub AutoNew()
    ' First part operates only in template other than "Kenyon Legal
    Letter.dot"
    ' Brings in Headers and styles from "Kenyon Legal Letter.dot"
    ' Revised 28 January 2004
    '
    ' Designed to allow changes in main letterhead headers or styles to
    ' automatically propogate in forms created by using SaveAs
    ' from that template.
    '
    ' The name of the Base Template ("Kenyon Legal Letter.dot") is stored
    ' as a document variable in that template. That variable's
    ' name is "BaseName." Templates created using the base template
    ' will also have the same variable.
    '
    ' If the name of the base template is changed, you need to change
    ' the variable in not only the base template but in
    ' every template that is based on it or this procedure
    ' will generate an error.
    '
        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
    ' Second part
    ' All new letters - show UserForm
        Dim myForm As frmAddress
        Set myForm = New frmAddress
        myForm.Show
        Unload myForm
        Set myForm = Nothing
    End Sub

    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)
        ' Altered to delete ranges 28 March 2004
        '
        ' 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.Delete
            rRange.InsertFile FileName:=WorkGroupPath _
                & "Letters & Faxes\" & sTemplateName, _
                Range:=sHeader, _
                ConfirmConversions:=False, Attachment:=False, Link:=False
            Set rRange = ActiveDocument.Bookmarks(sFooter).Range
            rRange.Delete
            rRange.InsertFile FileName:=WorkGroupPath _
                & "Letters & Faxes\" & sTemplateName, _
                Range:=sFooter, _
                ConfirmConversions:=False, Attachment:=False, Link:=False
        Next iCount
    End Sub

    This last procedure uses the range object.

    Note that I copy the styles in this by actually attaching the new doc to the
    base template. The OrganizerCopy method works well, too and I use it in some
    templates that have their own AutoText or other customizations. Mostly,
    though, attaching is simpler.

    The AutoNew finishes by calling up a form to get addressing (or other)
    information. Among other things, it allows the user to capture that
    information from previous letters rather than retyping it. This makes it a
    lot easier to get people to generate new letters rather than open an old one
    and SaveAs.

    My procedures work in Word 97-2003.

    In developing your letterhead you may want to take a look at: How to set up
    letterhead or some other document where you want one header on the first
    page and a different header on other pages.
    http://www.addbalance.com/word/headersfooters.htm This gives step-by-step
    instructions.

    Also take a look at:

    Letterhead Tips and Instructions
     http://home.zebra.net/~sbarnhill/Letterhead.htm

    Letterhead Textboxes and Styles tutorial
    http://addbalance.com/word/download/index.htm#LetterheadTextboxesAndStylesTutorial

    Template Basics
     http://www.addbalance.com/usersguide/templates.htm

    How to Create a Template - Part 2 - essential reading
    http://www.mvps.org/word/FAQs/Customization/CreateATemplatePart2.htm

    Word "Forms"
     http://www.addbalance.com/word/wordwebresources.htm#Forms and

    Word for Word Perfect Users
     http://www.addbalance.com/word/wordperfect.htm if you are coming from a WP
    environment (or even if you are not).

    Hope this is of some help.

    -- 
    Charles Kenyon
    Word New User FAQ & Web Directory: http://addbalance.com/word
    Intermediate User's Guide to Microsoft Word (supplemented version of
    Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
    See also the MVP FAQ: 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.
    "Tom Esker" <tjesker@yahoo.com> wrote in message
    news:a96ddfc7.0405191054.2622730@posting.google.com...
    > I recorded a macro using Word 2002 that inserts letterhead into the
    > header of a new document based on a separate template file.  It works
    > great except that the font of the text in the header changes to
    > whatever font was used in the document.  How can I make the font in
    > the letterhead text stay put and not affect the font of the rest of
    > the text in the document? Below is the macro:
    >
    > Sub NewLH2()
    > '
    > '' Macro recorded 05/19/2004 by tje
    > '
    >     If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    >         ActiveWindow.Panes(2).Close
    >     End If
    >     If ActiveWindow.ActivePane.View.Type = wdNormalView Or
    > ActiveWindow. _
    >         ActivePane.View.Type = wdOutlineView Then
    >         ActiveWindow.ActivePane.View.Type = wdPrintView
    >     End If
    >     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    >     ChangeFileOpenDirectory "F:\DATA\Workgroup Templates\"
    >     Documents.Open FileName:="""D&B continous letterhead.dot""", _
    >         ConfirmConversions:=False, ReadOnly:=False,
    > AddToRecentFiles:=False, _
    >         PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
    >         WritePasswordDocument:="", WritePasswordTemplate:="", Format:=
    > _
    >         wdOpenFormatAuto
    >     If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    >         ActiveWindow.Panes(2).Close
    >     End If
    >     If ActiveWindow.ActivePane.View.Type = wdNormalView Or
    > ActiveWindow. _
    >         ActivePane.View.Type = wdOutlineView Then
    >         ActiveWindow.ActivePane.View.Type = wdPrintView
    >     End If
    >     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    >     Selection.WholeStory
    >     Selection.Copy
    >     Selection.Find.ClearFormatting
    >     With Selection.Find
    >         .Text = ""
    >         .Replacement.Text = ""
    >         .Forward = True
    >         .Wrap = wdFindAsk
    >         .Format = False
    >         .MatchCase = False
    >         .MatchWholeWord = False
    >         .MatchWildcards = False
    >         .MatchSoundsLike = False
    >         .MatchAllWordForms = False
    >     End With
    >     Selection.Copy
    >     ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    >     Windows(2).Activate
    >     Selection.PasteAndFormat (wdPasteDefault)
    >     Selection.TypeBackspace
    >     ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    > End Sub
    >
    > Thanks
    > Tom Esker
    

  • Next message: Jean-Guy Marcil: "Re: Replacing spaces with 1 space or a tab"

    Relevant Pages

    • Re: Inserting Logo in Header
      ... Try putting the AutoText into a separate global template. ... The template always has the logo (which can also be an AutoText ... > a letterhead logo, which has been saved as AutoText into the header. ...
      (microsoft.public.word.vba.general)
    • Re: using letterhead automatically
      ... (that is with headers, with different first page header, without hearders, ... different types of letters for which a single template setup would not ... template with the letterhead and one without. ... When you create an AutoText, ...
      (microsoft.public.word.vba.general)
    • Re: Inserting Logo in Header
      ... I *AM* using a template. ... logo, which has been saved as AutoText into the header. ... the user can later change from the NY to the DC letterhead. ...
      (microsoft.public.word.vba.general)
    • Re: AutoText entry
      ... Those templates can call in or incorporate aspects of a base template as ... Letterhead Tips and Instructions ... > header with "Page 2", ... > using an AutoText entry with a button on the toolbar ...
      (microsoft.public.word.formatting.longdocs)
    • Re: Automatically Updating Custom Templates on Many Computers
      ... The way I do it is to have one base letterhead templates. ... An autonew macro in the template ... it finds the base template and copies the letterhead ... boilerplate text in AutoText. ...
      (microsoft.public.word.docmanagement)