Thursday, April 25, 2019

How can I easily toggle display of page breaks for all worksheets in an Excel 2010 workbook?

Excel 2010 only allows turning page breaks off or on for one worksheet at a time via File → Options → Advanced → "Display options for this Worksheet":


enter image description here


I previously came up with a VBA macro to toggle page breaks, but it only works on the sheet I have active:


Sub TogglePageBreaks()
ActiveSheet.DisplayPageBreaks = Not ActiveSheet.DisplayPageBreaks
End Sub

The next logical question (which someone else had to point out to me) is how do I use a macro to toggle page breaks display for all worksheets in the active workbook?


Being new to VBA, I spent a couple hours researching how to loop through worksheets and also how the DisplayPageBreaks object works. I came up with an answer below.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...