PDA

View Full Version : Solved: Set all sheets to pagebreak preview.



wilg
04-23-2011, 04:04 PM
I have this to set active window to pagebreak preview..

ActiveWindow.View = xlPageBreakPreview


But I want to automatically loop through all worksheets and set them all to pagebreak preview. Any way to do this?

Thanks to all of you for you support.

Kenneth Hobs
04-23-2011, 05:15 PM
This works for each sheet that has data.
For Each ws In ActiveWorkbook.Windows
ws.View = xlPageBreakPreview
Next ws

wilg
04-24-2011, 01:35 PM
I get an error of method or data not found and highlights

.View =

Sub work()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Windows
ws.View = xlPageBreakPreview
Next ws
End Sub

Kenneth Hobs
04-24-2011, 03:02 PM
I was trying some other things. Try this:
Sub work()
Dim ws As Worksheet, tws As Worksheet
Set tws = ActiveSheet
For Each ws In Worksheets
ws.Activate
ActiveWindow.View = xlPageBreakPreview
Next ws
tws.Activate
End Sub

wilg
04-24-2011, 06:12 PM
Hi Kennith. your code works. But as in my workbook I have 250 sheets so as you have each sheet activate it is very slow. But it does work. Thanks very much for all your help.

Kenneth Hobs
04-25-2011, 05:31 AM
If you turn screen updating off, that might speed it up.

For that method and others, see my speedup kb entry. The SpeedOn and SpeedOff routines make it easy to use. http://www.vbaexpress.com/kb/getarticle.php?kb_id=1035