View Single Post
 
Old 11-01-2020, 11:46 AM
ajgarrison ajgarrison is offline Windows 10 Office 2013
Novice
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

Thank you. I believe I found some of your code after I posted.
Code:
    'Deletes last section of a document including the section break - this fixes the problem with the last page having wrong header/footer
   
    Dim rng As Range
    Dim ctr As Integer
    Set doc = Wrd.ActiveDocument
    ctr = doc.Sections.Count
    Set rng = doc.Sections(ctr).Range
    Dim hf As HeaderFooter
    If ctr > 1 Then
        With rng
        'Added lines to "inherit" the settings from the next-to-last section
            For Each hf In .Sections(1).Headers
                hf.LinkToPrevious = True
                hf.LinkToPrevious = False
            Next
            For Each hf In .Sections(1).Footers
             hf.LinkToPrevious = True
             hf.LinkToPrevious = False
            Next

            .Select
            .MoveStart Unit:=wdCharacter, Count:=-1
            .Delete
        End With
    End If
    '--------------This addresses the blank last page-----------
    With Wrd.ActiveDocument.Characters.Last
        While .Previous.Text Like "[ " & Chr(160) & vbCr & vbTab & Chr(12) & "]"
        .Previous.Text = vbNullString
        Wend
    End With
This works perfectly except when last page is landscape, not it has changed to portrait.

Thank you.

Last edited by macropod; 11-01-2020 at 09:29 PM. Reason: Added code tags
Reply With Quote