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