Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference Current Worksheet, Run Macro, Come Back to Current Sheet 1

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hi

In Excel, setting the zoom control only applies to the worksheet you're working on and not the whole workbook. I created a "zoom all" macro so that all worksheets would show the same size.

In the macro, it runs through all visible sheets but how can I get it to bring focus back to the sheet it started on? For example, if I invoke it on sheet 6 I want it to run and come back to sheet 6 when it ends. Thanks very much.

Code:
Sub zoom_choice()
Dim response
Dim canceltest As Variant
Dim x As Integer
Dim ws As Worksheet

Application.ScreenUpdating = False
response = InputBox("Enter the zoom magnification you would like")

If StrPtr(response) = 0 Then
MsgBox "Cancelled", vbOKOnly, "Cancel Zoom"
Else

For Each ws In Worksheets
If ws.Visible Then ws.Activate
ActiveWindow.zoom = response
Next

Application.ScreenUpdating = True
End If
End Sub
 
Like this ?
Code:
...
Application.ScreenUpdating = False
response = InputBox("Enter the zoom magnification you would like")
If StrPtr(response) = 0 Then
    MsgBox "Cancelled", vbOKOnly, "Cancel Zoom"
Else
    Dim s As Worksheet: Set s = ActiveSheet
    For Each ws In Worksheets
        If ws.Visible Then ws.Activate
        ActiveWindow.zoom = response
    Next
    s.Activate
End If
Application.ScreenUpdating = True
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you so much, PHV! Works perfectly!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top