Generalize sub to work on all open books and views

M

Max

How could the sub below be generalized to work on all simultaneously open
books and views (I may have some books open with multiple windows)? The sub
currently works only on the activebook/view (where the cursor is). Thanks

Sub NoGridLinesZoom75()
Dim ws As Worksheet
Dim wsht As Worksheet
Set wsht = ActiveSheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75
Next
wsht.Select
End Sub
 
P

Per Jessen

Hi

Try this:

Sub NoGridLinesZoom75()
Dim wbk As Workbook
Dim ws As Worksheet
Dim wsht As Worksheet
Application.ScreenUpdating = False
Set wsht = ActiveWorkbook.ActiveSheet
For Each wbk In Application.Workbooks
For Each ws In wbk.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75
Next
Next
wsht.Select
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
P

Patrick Molloy

Sub NoGridLinesZoom75()
Dim ws As Worksheet
Dim wsht As Worksheet dim wb as workbook
Set wsht = wb.ActiveSheet
for each wb in workbooks
wb.activate
For Each ws In wb.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75
Next
wsht.Select
next
End Sub
 
M

Max

The sub halted here when I tried it:Runtime error 91, object variable or with block variable not set
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top