locked
Word Landscape page Macro RRS feed

  • Question

  • Greetings,
    I am trying to utilize a macro which inserts a landscape page in my document. I am using a specific custom layout as per the headers and the footers on the document. The landscape page I wish to insert in the document should obtain the same headers and footers and continue with the numbering. Unfortuantely, This macro inserts the landscape page however, It does it without the headers and footers and it also messes up the headers and footers for the page afterwards.

    Sub Macro2()
        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)
            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
    
    
    
    End Sub
    

    Tuesday, October 14, 2014 6:40 AM

All replies

  • Hi Grech,

    In at least 3 separate locations within your code you are referencing the headers and footers and in each case you are unlinking them from previous. You need to change "False" to "True" if you want them linked. Here is one example:

    .Headers(j).LinkToPrevious = True
    .Footers(j).LinkToPrevious = True

    Now you should also recognize that the headers and footers are setup for Portrait orientation and thus tab stops may need to be adjusted in the Landscape oriented page headers and footers if you want the data they contain to align properly.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, October 14, 2014 12:42 PM
  • Greetings Rich,

    I have previously tried that and tried it once again now, unfortunately it does not fix the problem nor change the outcome.

    Regards,

    R. Grech

    Wednesday, October 15, 2014 6:38 AM
  • Hi R. Grech,

    Since this issue is related to Office for developing, This forum is for general questions and feedback related to Wordand this forum is for general questions and feedback related to Word.

    I recommend you post this issue on the Office for developer forum for better assistance.

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,

    Greta Ge
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs.

    Friday, October 24, 2014 1:23 AM