Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Same as Previous in Header (XP/SR3)

    I'm trying to write a macro that will help with typesetting a book. I want to change an odd page header in a given section and get rid of the wretched 'same as previous'.
    When I record this, I get the line generated
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
    LinkToPrevious
    But when I run the macro, I get a runtime 91 error message--object variable or block variable not set.
    Can anyone suggest the code I have to put in. And/or, is there any way of overcoming Word's defaulting to 'Same as Previous'?

    many thanks

    Philip

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Same as Previous in Header (XP/SR3)

    That bit of code will only work if the selection is within the header. To unlink the header of the 2nd section from that of the 1st section, you can use

    ActiveDocument.Sections(2).Headers(wdHeaderFooterP rimary).LinkToPrevious = False

    It doesn't matter where the selection is when you run this.

    And no, I don't think you can turn 'Same as Previous' off by default.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Same as Previous in Header (XP/SR3)

    I use code to do this regularly. The following snippet along with the called function should get you going. Note that this code isolates the current section from both the subsequent section and the preceding section.

    <pre> Dim iSect As Integer
    Dim iSectCount As Integer
    iSectCount = ActiveDocument.Sections.Count
    iSect = Selection.Sections.First.Index

    'call function to stop headers and footers impacting surrounding sections
    SetIndepHF iSectCount, iSect
    '=======================
    Public Function SetIndepHF(iSectCount As Integer, iSect As Integer)
    'Stop subsequent linking of headers and footers
    With ActiveDocument.Range
    If iSect < iSectCount Then
    .Sections(iSect + 1).Headers(wdHeaderFooterPrimary).LinkToPrevious = False
    .Sections(iSect + 1).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
    Else
    .Sections(iSect).Headers(wdHeaderFooterPrimary).Li nkToPrevious = False
    .Sections(iSect).Footers(wdHeaderFooterPrimary).Li nkToPrevious = False
    End If
    If iSect > 1 Then
    .Sections(iSect).Headers(wdHeaderFooterPrimary).Li nkToPrevious = False
    .Sections(iSect).Footers(wdHeaderFooterPrimary).Li nkToPrevious = False
    .Sections(iSect).PageSetup.DifferentFirstPageHeade rFooter = False
    End If
    End With
    End Function</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Same as Previous in Header (XP/SR3)

    thanks very much to both--that's enabled me to sort it, I think.

Posting Permissions

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