Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Remove header/footer from a landscape page inserted in between 2 portrait

    Hey All,

    I have this code which inserts a landscapes formatted page between 2 portrait pages, the problem i am having is i want to remove the header and footer from the landscape page as it looks ugly if i leave them in the doc.

    Any help? I have tried the WordBasic.RemoveHeader and WordBasic.RemoveFooter code but it removes the header from the preceding portrait page as well.

    I assume its an easy fix but i just can't figure it out, any help would be great

    Code:
    Sub LandscapePage()
    ' Landscape Macro
    '
    '
    Dim rng As Range
    Dim i As Long, j As Long
    Set rng = Selection.Range
    rng.start = ActiveDocument.Range.start
    i = rng.Sections.Count
    rng.Collapse wdCollapseEnd
    rng.InsertBreak wdSectionBreakNextPage
    rng.InsertBreak wdSectionBreakNextPage
    With ActiveDocument.Sections(i + 2)
        For j = 1 To .Headers.Count
            .Headers(j).LinkToPrevious = False
            .Footers(j).LinkToPrevious = False
        Next j
    End With
    With ActiveDocument.Sections(i + 1)
        WordBasic.RemoveHeader
        WordBasic.RemoveFooter
        For j = 1 To .Headers.Count
            With .Headers(j)
                .LinkToPrevious = False
                .LinkToPrevious = False
                If .Range.Tables.Count > 0 Then
                    With .Range.Tables(1)
                        .PreferredWidthType = wdPreferredWidthPoints
                        .PreferredWidth = CentimetersToPoints(26.5)
                    End With
                End If
            End With
            With .Footers(j)
                .LinkToPrevious = False
                .LinkToPrevious = False
                If .Range.Tables.Count > 0 Then
                    With .Range.Tables(1)
                        .PreferredWidthType = wdPreferredWidthPoints
                        .PreferredWidth = CentimetersToPoints(26.5)
                    End With
                End If
            End With
        Next j
        With .PageSetup
            .LineNumbering.Active = False
            .Orientation = wdOrientLandscape
            .TopMargin = CentimetersToPoints(2)
            .BottomMargin = CentimetersToPoints(1.5)
            .LeftMargin = CentimetersToPoints(2)
            .RightMargin = CentimetersToPoints(1.5)
            .HeaderDistance = CentimetersToPoints(1.5)
            .FooterDistance = CentimetersToPoints(0.1)
            .PageWidth = CentimetersToPoints(29.7)
            .PageHeight = CentimetersToPoints(21)
        End With
    End With

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Why did you remove the header and footer BEFORE turning off LinkToPrevious in section i + 1?

    I would have expected that if the header was linked to previous then deleting it would delete the preceding header as well.

    FWIW, I usually get the current section number with the following
    iSect = Selection.Sections.First.Index
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I've tried removing it all over the shop and it doesnt seem to work anywhere, at least this bit actually removes from the landscaped page

Posting Permissions

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