Results 1 to 10 of 10
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    NJ, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating fields in Multiple Header/Footers

    Hello,

    I have tried searching the forums for help, but can't seem to find anything that is quite what I am looking for. I need help with Word 97 headers/footers.
    I have a document that has multiple sections with different Headers/Footers. I would like to have a macro that will open the first header/footer and perform x, then will move to each header/footer in the doc and also perform x until there are no more headers/footers in the document.
    Can anyone help me? Thanks in advance!

    Magella

  2. #2
    Star Lounger
    Join Date
    Dec 2000
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Use this as your skeletal code:

    '************************************************* ***
    Sub ManipulateAllHeadersFooters()
    Dim aSect As Section

    For Each aSect In ActiveDocument.Sections

    'Do your thing to the primary header
    With aSect.Headers(wdHeaderFooterPrimary)
    'Perform x...
    End With

    'Repeat for primary footer
    With aSect.Footers(wdHeaderFooterPrimary)
    'Perform x...
    End With

    'If first page header/footer exists, then repeat for those too
    If aSect.Headers(wdHeaderFooterFirstPage).Exists Then

    With aSect.Headers(wdHeaderFooterPrimary)
    'Perform x...
    End With

    With aSect.Footers(wdHeaderFooterPrimary)
    'Perform x...
    End With

    End If

    'Finally, if even page header/footer exists, then repeat for those as well
    If aSect.Headers(wdHeaderFooterEvenPages).Exists Then

    With aSect.Headers(wdHeaderFooterEvenPages)
    'Perform x...
    End With

    With aSect.Footers(wdHeaderFooterEvenPages)
    'Perform x...
    End With

    End If
    Next aSect

    End Sub
    '************************************************* ***

    BTW, in this example, you should not think in terms of the code "opening" each header/footer. Instead, think in terms of it simply "acting" on each header/footer object.

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    NJ, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Hello Stephan,

    Thank-you for your response - unfortunately, it doesn't quite work. I have tried something like this but it never seems to find the next section - it will repeat the instructions (which are to insert an autotext entry into the header) twice for the header of the first section but never seems to understand that another section exists. I can't get it to "move on" to the next section. Any other ideas?
    Your help is greatly appreciated!
    Thanks,
    magella

  4. #4
    Star Lounger
    Join Date
    Dec 2000
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    That shouldn't be happening.

    Why don't you post a small sample of your code.

  5. #5
    Lounger
    Join Date
    Jan 2001
    Location
    NJ, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Hi Stephan,

    Here is what I added directly to the code example you gave me:

    Dim aSect As Section

    For Each aSect In ActiveDocument.Sections

    'Do your thing to the primary header
    With aSect.Headers(wdHeaderFooterPrimary)
    With ActiveWindow.View
    .Type = wdPageView
    .SeekView = wdSeekCurrentPageHeader
    End With
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=Selection.Range
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End With


    'If first page header/footer exists, then repeat for those too
    If aSect.Headers(wdHeaderFooterFirstPage).Exists Then

    With aSect.Headers(wdHeaderFooterPrimary)
    With ActiveWindow.View
    .Type = wdPageView
    .SeekView = wdSeekCurrentPageHeader
    End With
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=Selection.Range
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End With

    End If

    'Finally, if even page header/footer exists, then repeat for those as well
    If aSect.Headers(wdHeaderFooterEvenPages).Exists Then

    With aSect.Headers(wdHeaderFooterEvenPages)
    With ActiveWindow.View
    .Type = wdPageView
    .SeekView = wdSeekCurrentPageHeader
    End With
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=Selection.Range
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End With

    End If
    Next aSect

    End Sub


    Originally I just added the insert autotext command as I was trying to follow your advice to not worry about "opening" the headers/footers, but without opening the Header, the autotext entry is just added to the first page, not the header.
    Thanks for your help!
    magella

  6. #6
    Star Lounger
    Join Date
    Dec 2000
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Try this:

    '************************************************* *****
    Sub ManipulateAllHeadersFooters()
    Dim aSect As Section

    For Each aSect In ActiveDocument.Sections

    'Do your thing to the primary header
    With aSect.Headers(wdHeaderFooterPrimary)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    'Repeat for primary footer
    With aSect.Footers(wdHeaderFooterPrimary)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    'If first page header/footer exists, then repeat for those too
    If aSect.Headers(wdHeaderFooterFirstPage).Exists Then

    With aSect.Headers(wdHeaderFooterFirstPage)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    With aSect.Footers(wdHeaderFooterFirstPage)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    End If

    'Finally, if even page header/footer exists, then repeat for those as well
    If aSect.Headers(wdHeaderFooterEvenPages).Exists Then

    With aSect.Headers(wdHeaderFooterEvenPages)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    With aSect.Footers(wdHeaderFooterEvenPages)
    'Perform x...
    NormalTemplate.AutoTextEntries("DRAFT").Insert Where:=.Range
    End With

    End If
    Next aSect

    End Sub
    '************************************************* *****

    See what I mean about not having to open each header/footer? Notice all I do in each case is set the range of header/footer (instead of the range of the selection) to be the autotext entry.

    BTW, I gave you some slightly buggy code before, so get rid of the whole thing and use the above.

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    NJ, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Hello and Thank-you! That worked perfectly!

    Thanks,
    magella

  8. #8
    Star Lounger
    Join Date
    Dec 2000
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    Good, happy to hear it.

    By the way, do you have a copy of "Learning Word Programming" by Steven Roman (Publisher: O'Reilly)? If you don't, get it. A lot of the code I gave you here was taken directly from that book.

  9. #9
    Lounger
    Join Date
    Jan 2001
    Location
    NJ, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating fields in Multiple Header/Footers

    No, I have heard of it though and now I will be sure to pick up a copy. Thanks again for your help!

  10. #10
    kelliel
    Guest

    Re: Updating fields in Multiple Header/Footers

    See the included attachment for a little tighter code. This has worked on all variations/combinations possible with Sections and Headers/Footers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •