How to Lock the Zoom in Excel Using VBA – 7 Steps

 Step 1 – Open the VBA Window

  • Press ALT+F11 to open the VBA window.
  • Select Insert >> Module.

Lock zoom in excel


Step 2 – Create the Sub Procedure

Sub LockZoomInExcel()

End Sub
You will enter the code inside this subject procedure.

Step 3 – Add a Do Loop to Lock the Zoom

Sub LockZoomInExcel()
Do

Loop While True
End Sub
The statement inside this Do…Loop forces VBA to reset the zoom to a defined value, whenever it is changed.

Step 4 – Add an IF Statement to Reset the Zoom

Sub LockZoomInExcel()
Do
If ActiveWindow.Zoom <> 100 Then
ActiveWindow.Zoom = 100
End If
Loop While True
End Sub
The If statement sets the zoom to 100%.

Step 5 – Include a DoEvents Statement

(Here you get the complete code)

Sub LockZoomInExcel()
Do
If ActiveWindow.Zoom <> 100 Then
ActiveWindow.Zoom = 100
End If
DoEvents
Loop While True
End Sub
The DoEvents statement allows you to stop the running macro.

Step 6 – Run the Code

  • Keep the cursor on the code and press F5 to run it.
  • Go back to the worksheet.

how to lock zoom in excel


Step 7 – Observe the Results

You won’t be able to zoom the page.

You need to run the code every time you reopen the document.


Things to Remember

  • Save the file as a macro-enabled workbook.

Download Practice Workbook

Download the Excel file.


Related Articles


<<Go Back to How to Zoom in Excel | Excel Worksheets | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Shamim Reza
Md. Shamim Reza

Md. Shamim Reza, a marine engineer with expertise in Excel and a fervent interest in VBA programming, sees programming as a time-saving tool for data manipulation, file handling, and internet interaction. His diverse skill set encompasses Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning. He holds a B.Sc in Naval Architecture & Marine Engineering from BUET and has transitioned into a content developer role, generating technical content focused on Excel and VBA. Beyond his professional pursuits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo