VBA – Zoom in and Out of Worksheets


You can use VBA to change the Zoom of a worksheet. Here’s code to change the Zoom of the ActiveWindow to 50%:

ActiveWindow.Zoom = 50

Change Zoom on all Worksheets

You can also loop through all the worksheets in your workbook to set a standard Zoom. The following Macro will set the Zoom for all worksheets to 50%:

Sub ZoomAll()

Dim ws As Worksheet

Application.ScreenUpdating = False

For Each ws In Worksheets


    ActiveWindow.Zoom = 50


Application.ScreenUpdating = True

End Sub

Zoom Zoom

And finally a magically growing worksheet. The following macro will loop through the Zooms for Sheet1, going from 10% to 200%, incrementing by 10%, pausing a second between changes, and then it will restore Sheet1 back to it’s original state.

Sub ZoomZoom()

Dim x As Integer 'variable for loop

Dim OriginalZoom As Integer 'variable for original zoom

Sheet1.Activate 'let's work with sheet1

OriginalZoom = ActiveWindow.Zoom 'get current zoom

'loop through zoom 10 to 200 by 10

    For x = 1 To 20

        ActiveWindow.Zoom = x * 10

        Application.Wait Now + TimeValue("00:00:01")

    Next x


'restore original zoom

ActiveWindow.Zoom = OriginalZoom

End Sub

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!

<<Return to VBA Examples

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)