Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
(I don't have Excel 2010) Can you not group the sheets and click on something like Page Break Preview? – pnuts Jun 7 '13 at 21:41

Here's what I was able to come up with. I tested it successfully in Excel 2010. I'm very new to VBA so I struggled with this for a while. ws.Activate was the key, since DisplayPageBreaks only applies to the active sheet. Credit to RocketDonkey's post for making me realize that. Credit also to Rick Rothstein for the beautifully simple toggle code concept which I applied in my answer.

Sub ToggleWkBkPageBreaks()

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets


        ActiveSheet.DisplayPageBreaks = True + False - ActiveSheet.DisplayPageBreaks

    Next ws

End Sub
share|improve this answer
@Oliver Salzburg - thank you very much for improving my question by adding the screenshot. I should have thought of that. Still learning forum best practices as I learn VBA! – AMM Jun 7 '13 at 20:27
That's fine, I'm happy to help. Thanks for contributing! :) – Oliver Salzburg Jun 7 '13 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .