无法删除额外的分页符

Trouble Removing extra page Break

我有一些代码可以以可打印格式在临时工作表上创建报告。在该代码中,它调用 Sub SetPageBreaks (代码下方)。我在删除列 G:H.

之间设置的特定分页符时遇到问题
Sub SetPageBreaks(SheetObj As Worksheet)

    Dim TotRow%, LinesPerPg%, NumPgs%, Page%

    TotRow = SheetObj.UsedRange.Rows.Count
    LinesPerPg = 56
    NumPgs = RoundUp(TotRow / LinesPerPg)

    With SheetObj
        .ResetAllPageBreaks
        For Page = 1 To NumPgs
            .Rows(LinesPerPg * Page + 1).PageBreak = xlPageBreakManual
        Next Page
        .Columns("J").PageBreak = xlPageBreakManual
        .Columns("H").PageBreak = xlPageBreakNone
    End With

End Sub

Function RoundUp(ByVal Number As Double) As Long
    RoundUp = Application.WorksheetFunction.RoundUp(Number, 0)
End Function

Between columns I:J 是页面的最后一列(它需要适合页面的整个宽度,一些缩放是可以预期的)。为什么我的代码没有删除 col H?

上的中断

编辑(新的编码尝试):

我已将我的代码更新为以下内容,但没有成功(根据我的喜好调整边距,然后添加 .FitToPagesWide,这是我最后一列的剪切。

Option Explicit

Sub SetPageBreaks(SheetObj As Worksheet)

    Dim TotRow%, LinesPerPg%, NumPgs%, Page%

    TotRow = SheetObj.UsedRange.Rows.Count
    LinesPerPg = 56
    NumPgs = RoundUp(TotRow / LinesPerPg)

    With SheetObj
        .ResetAllPageBreaks
        For Page = 1 To NumPgs
            .Rows(LinesPerPg * Page + 1).PageBreak = xlPageBreakManual
        Next Page
        With .PageSetup
            .HeaderMargin = 21.6
            .FooterMargin = 21.6
            .TopMargin = 86.4
            .LeftMargin = 18
            .RightMargin = 18
            .BottomMargin = 54
            .FitToPagesWide = 1
            .FitToPagesTall = False
        End With
    End With

End Sub

要进行某些缩放,您必须让 Excel 知道如何进行。在 With 块的开头,添加:

.PageSetup.Zoom = False
.PageSetup.PrintArea = "$A:$I"
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = False

您的最后 2 行 With 块行应该不再需要了。