试图打印2页高的PDF,并在行号“ numrows2” bu处接收分页符
With Sheets("offer_Sheet").PageSetup
.PrintArea = ("A2:H" & numrows)
.HPageBreak.Location = ("A: " & numrows2)
.FitToPagesWide = 1
.FitToPagesTall = 2
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.1)
.BottomMargin = Application.InchesToPoints(0.1)
.HeaderMargin = Application.InchesToPoints(0.1)
.FooterMargin = Application.InchesToPoints(0.1)
.Orientation = xlPortrait
End With
答案 0 :(得分:0)
PageSetup
没有HPageBreak
属性。
如果要添加HPageBreak
,则可以使用HPageBreaks.Add
:
Sub test()
Dim numrows As Long, numrows2 As Long
numrows = 20
numrows2 = 10
With Sheets("offer_Sheet")
.HPageBreaks.Add (.Range("A" & numrows2))
With .PageSetup
.PrintArea = ("A2:H" & numrows)
.FitToPagesWide = 1
.FitToPagesTall = 2
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.1)
.BottomMargin = Application.InchesToPoints(0.1)
.HeaderMargin = Application.InchesToPoints(0.1)
.FooterMargin = Application.InchesToPoints(0.1)
.Orientation = xlPortrait
End With
End With
End Sub
或者,如果您要修改现有的HPageBreak
,也许:
Sub test2()
Dim numrows As Long, numrows2 As Long
numrows = 20
numrows2 = 11
With Sheets("offer_Sheet")
If .HPageBreaks.Count > 0 Then
Set .HPageBreaks(1).Location = .Range("A" & numrows2)
End If
With .PageSetup
.PrintArea = ("A2:H" & numrows)
.FitToPagesWide = 1
.FitToPagesTall = 2
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.1)
.BottomMargin = Application.InchesToPoints(0.1)
.HeaderMargin = Application.InchesToPoints(0.1)
.FooterMargin = Application.InchesToPoints(0.1)
.Orientation = xlPortrait
End With
End With
End Sub