Zoom in and Out of Worksheet in VBA

You might want to zoom in and out of a worksheet using Excel VBA for several reasons. For example, if you have created a custom user interface, you might want to allow users to zoom in and out of a worksheet for a better user experience.

This tutorial shows how to zoom in and out of an Excel worksheet using Excel VBA.

How to Zoom in and Out of Worksheet Using Excel VBA

To zoom in and out of a worksheet in VBA, you can use the Zoom method of the Worksheet object. The Zoom method takes a percentage value as its argument, which specifies the zoom level. Note that the minimum zoom level in Excel is 10%, and the maximum is 400%.

We want to zoom in on the active worksheet by 50% and zoom out by 50% after five seconds. We use the below steps:

  1. On the active worksheet, press Alt + F11 to open the Visual Basic Editor.
  2. Open the Insert menu and choose Module to create a module.
Graphical user interface, application, Word

Description automatically generated
  1. Copy the sub-routine below and paste it into the module.
  1. Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm).
  2. Place the cursor anywhere in the sub-routine and press F5 to run the code.

This code zooms in the active worksheet by 50%, waits for 5 seconds, and zooms out by 50%. Of course, you can change the zoom percentages and wait time per your requirement.

Conclusion

This tutorial showed that one of the reasons you might want to write a macro for zooming in and out of a worksheet using Excel VBA is to allow users to zoom in and out of a worksheet for a better user experience.

This tutorial showed how to zoom in and out of an Excel worksheet using Excel VBA. We hope you found the tutorial helpful.

Tomasz Decker is an Excel specialist, skilled in data analysis and financial modeling.

Posted in vba