Change Zoom levels on Excel Sheets using VBA

Manuprasad

New Member
Joined
May 24, 2016
Messages
39
I have a VBA that will set the zoom level based on the screen resolution.But its working only for ActiveWindow when you open workbook.
How can I add this across all worksheets in Excel?


Code:
<code>Declare Function GetSystemMetrics32 Lib "user32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Public Sub ScreenRes()
    Dim lResWidth As Long
    Dim lResHeight As Long
    Dim sRes As String

    lResWidth = GetSystemMetrics32(0)
    lResHeight = GetSystemMetrics32(1)
    sRes = lResWidth & "x" & lResHeight
    Select Case sRes
        Case Is = "800x600"
            ActiveWindow.Zoom = 75
        Case Is = "1024x768"
            ActiveWindow.Zoom = 125
        Case Else
            ActiveWindow.Zoom = 100
    End Select
End Sub</code>

I will call this module on the Workbook

Code:
<code>Private Sub Workbook_Open()
ScreenRes
End Sub</code>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Just loop through the worksheets?

Something like:

Code:
Dim ws As Worksheet

    For Each ws In Worksheets
        ws.Select
        ActiveWindow.Zoom = 85 //change as per your requirements
    Next ws
 
Upvote 0
Maybe this:
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ScreenRes
 
Upvote 0
Thanks for your reply!! Not just loop through Sheets. I also want to make sure zoom level across all the worksheets are set based on screen resolution. As of now, with my above code Zoom level is only set for first page when the workbook is open. How do I loop through the sheets keeping screen resolution on mind?
 
Upvote 0
Wow!! that worked. BRAVO....Just that code will activate only when I click on sheet....but my intention was to activate zoom level when the workbook open. However, the code serves the purpose at the moment. If you have suggestions to activate zoom level when workbook opens, please let me know.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top