Excel VBA to Clear Manual Page Breaks

Be careful how you do it

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.

 

Please note: I reserve the right to delete comments that are offensive or off-topic.

Leave a Reply

Your email address will not be published. Required fields are marked *

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