我有一些代码可以打印到可打印格式的临时工作表。在该代码中,它调用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
列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
答案 0 :(得分:0)
要进行某些缩放,您必须让Excel知道如何进行缩放。在With块的开头,添加:
.PageSetup.Zoom = False
.PageSetup.PrintArea = "$A:$I"
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = False
您的最后2个不再需要使用块行。