Excel VBA to Clear Manual Page Breaks

When clearing page breaks in Excel VBA you need to be careful. There is one command that will clear page breaks but it will also affect other print settings.

If you use

ActiveSheet.ResetAllPageBreaks

You may also reset many other print settings.

To remove just the page breaks it can be better to use

ActiveSheet.Cells.PageBreak = xlPageBreakNone

If the sheet is using the Page Break Preview View the above line of code will crash the macro. It is safer to use the following two lines of code.

ActiveWindow.View = xlNormalView
ActiveSheet.Cells.PageBreak = xlPageBreakNone

This avoids crashing the macro.

 

This Post Has One Comment

  1. Sandeep

    Dear Neale, Wonderful codes. One question: how is the last code different from the code
    ActiveSheet.displaypagebreaks = False?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.