ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Generalize sub to work on all open books and views (https://www.excelbanter.com/excel-programming/431259-generalize-sub-work-all-open-books-views.html)

Max

Generalize sub to work on all open books and views
 
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

Per Jessen[_2_]

Generalize sub to work on all open books and views
 
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


On 17 Jul., 15:55, Max wrote:
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



Patrick Molloy

Generalize sub to work on all open books and views
 
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

"Max" wrote in message
...
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



Max

Generalize sub to work on all open books and views
 
The sub halted here when I tried it:
Set wsht = wb.ActiveSheet

Runtime error 91, object variable or with block variable not set



Max

Generalize sub to work on all open books and views
 
Thanks, Per. Tried it out, and it works fine

Max




All times are GMT +1. The time now is 05:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com