• Same as Previous in Header (XP/SR3)

    Author
    Topic
    #448542

    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

    Viewing 1 reply thread
    Author
    Replies
    • #1097159

      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(wdHeaderFooterPrimary).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.

    • #1097180

      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.

        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  1 Then
            .Sections(iSect).Headers(wdHeaderFooterPrimary).LinkToPrevious = False
            .Sections(iSect).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
            .Sections(iSect).PageSetup.DifferentFirstPageHeaderFooter = False
          End If
        End With
      End Function
      • #1097313

        thanks very much to both–that’s enabled me to sort it, I think.

    Viewing 1 reply thread
    Reply To: Same as Previous in Header (XP/SR3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: