none
Importing header and footer from a separate document for use in multiple templates?

    Question

  • I've been playing with Word 2007 and pulling in content for a template from other word documents. The goal is to have a number of templates deployed for people to use and for the administrators of these templates be able to update the "re-usable" portions like the headers and footers by updating one file instead of 100 .

    So far I can pull the header information into the template from the other document, but I have been unable to adjust the margins in the template document based on the margins that are set in the "header" source document. Quite often the margins are changing for these things so it would be fairly useless to go to the trouble of setting it up to pull content in if it cannot also pull in the layout/margins (ie - force the template document to take the margins dictated by the header document)

    Is this just a pipe dream? Thanks for any input you can provide.

    Thursday, October 28, 2010 8:56 PM

All replies

  • Assuming that the 100 refers to users and not templates, see the article "Distributing macros to other users” at:

    http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm


    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Sixxxxx" wrote in message news:a64da3a1-afff-445f-ba5a-2024c2ff1aee@communitybridge.codeplex.com...

    I've been playing with Word 2007 and pulling in content for a template from other word documents. The goal is to have a number of templates deployed for people to use and for the administrators of these templates be able to update the "re-usable" portions like the headers and footers by updating one file instead of 100 .

    So far I can pull the header information into the template from the other document, but I have been unable to adjust the margins in the template document based on the margins that are set in the "header" source document. Quite often the margins are changing for these things so it would be fairly useless to go to the trouble of setting it up to pull content in if it cannot also pull in the layout/margins (ie - force the template document to take the margins dictated by the header document)

    Is this just a pipe dream? Thanks for any input you can provide.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Thursday, October 28, 2010 11:10 PM
  • The 100's actually refers to templates into which I want to import a standard header and footer from another source. Thus reducing admin time to change things when minor alignment changes are made.

    Your tip is good for another thing I'm working on, however, so thanks!

    Friday, October 29, 2010 1:18 PM
  • Sixxxxx wrote:

    So far I can pull the header information into the template from the
    other document, but I have been unable to adjust the margins in the
    template document based on the margins that are set in the "header"
    source document. Quite often the margins are changing for these
    things so it would be fairly useless to go to the trouble of setting
    it up to pull content in if it cannot also pull in the layout/margins
    (ie - force the template document to take the margins dictated by the
    header document)

    I don't think you're going to be able to make this work.

    In Word, the margins are properties of the current section (stored in the section break at the end of the section, or in the final paragraph mark  for the last or only section). Unless you're importing a section break as well as the header/footer, the import can't alter the template's current margins. The only relevant formatting at the paragraph level (which is what's available in the import) consists of the left and right indents, but they're relative to the existing margins.

    I think the only way you're going to achieve the desired formatting is to import each piece of the header/footer separately (using INCLUDETEXT fields with bookmark references), and use tabstops and tabs between the fields to position them at the margins. When any particular template's margins are changed, you'll have to be careful to move any "center" or "right" tabstops in the header and footer to match. Word 2010 finally introduced a "right margin" tabstop type that will make this less painful.


    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    Friday, October 29, 2010 1:51 PM
  • What you ask is feasible, but there are a number of provisos and more than one way of achieving what you require. How to approach the issue depends on the nature of the templates.
    If they are all basically the same layout with similar headers and footers it is a relatively simple job to run a batch process to change the header footers. You should also bear in mind that a template will have potentially three header & footer ranges for each section, so you would need to consider what header & footer information goes in which header & footer.

    If there is going to be changeable data, like addresses, phone numbers or names of key personnel, that is perhaps best dealt with by means of document variables or document properties, which can easily be written to by macro, when the need arises.

    The following is a batch macro that will open and allow changes to all templates in a folder. All you need now is to let us know what is in the headers and footers and what needs to replace it.

    Sub BatchProcessTemplates()
    Dim strFilename As String
    Dim strPath As String
    Dim oDoc As Document
    Dim fDialog As FileDialog
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

    With fDialog
        .Title = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled By User", , _
            "List Folder Contents"
            Exit Sub
        End If
        strPath = fDialog.SelectedItems.Item(1)
        If Right(strPath, 1) <> "\" _
        Then strPath = strPath + "\"
    End With

    If Documents.Count > 0 Then
        Documents.Close SaveChanges:=wdPromptToSaveChanges
    End If
    If Left(strPath, 1) = Chr(34) Then
        strPath = Mid(strPath, 2, Len(strPath) - 2)
    End If
    strFilename = Dir$(strPath & "*.dot?")

    While Len(strFilename) <> 0
        If InStr(1, LCase(strFilename), "normal.dot") = 0 Then
            WordBasic.DisableAutoMacros 1
            Set oDoc = Documents.Open(strPath & strFilename)
            '
            'Do what you want with oDoc e.g.
            MsgBox oDoc.Name
            '
            oDoc.Close SaveChanges:=wdSaveChanges
            WordBasic.DisableAutoMacros 0
        End If
        strFilename = Dir$()
    Wend
    End Sub



    <Sixxxxx> wrote in message news:922461dc-2790-4392-a1dd-d20109cfcfee@communitybridge.codeplex.com...

    The 100's actually refers to templates into which I want to import a standard header and footer from another source. Thus reducing admin time to change things when minor alignment changes are made.

    Your tip is good for another thing I'm working on, however, so thanks!


    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/
    Friday, October 29, 2010 2:13 PM
  • Thanks for the feedback, Jay. That was the answer I was coming up with but didn't want to hear. I just didn't want to have to go an physically open each document just to gently tweek a header margin.... I wanted to FORCE the change by updating it in one place... Alas...

     

    Friday, October 29, 2010 5:39 PM