matt_codingtyro
matt_codingtyro

Reputation: 81

Remove Automatic Page Breaks in VBA

Does anyone know whether you can remove automatic page breaks in Excel VBA? I finally found an article that says that you cannot, but I'd like to confirm. I'm a little disappointed that this can't be accomplished in VBA.

This code, in a subroutine, seems to be able to remove user-inserted or manual page breaks, but not ones inserted by Excel automatically.

For nCtr = 1 To ActiveSheet.HPageBreaks.Count
    ActiveSheet.HPageBreaks(1).DragOff Direction:=xlUp, RegionIndex:=1
Next

For nCtr = 1 To ActiveSheet.VPageBreaks.Count
    ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
Next

Thoughts?

Upvotes: 2

Views: 4010

Answers (1)

neo
neo

Reputation: 31

I think the only way you can "control" the automatically page breaks is modifying the PageSetup proprieties and column\rows widths.

With ActiveSheet.PageSetup
    .Zoom = False
    .FitToPagesWide = 1 'Set with to 1 page
    .FitToPagesTall = False 'Set height to Automatic
End With

Rows(1).RowHeight = 32
Columns(1).ColumnWidth = 25

Upvotes: 2

Related Questions