Setting the Zoom Level by User

Written by Allen Wyatt (last updated October 25, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


1

James's department has a workbook that is used by multiple people, but not at the same time. Each person has a different preference for what zoom setting should be used with the workbook. James wonders if there is a way to automatically set the zoom based on which person is opening the workbook.

There is no way to do this without enlisting the help of a macro. You can set up the Workbook_Open event handler to execute anything you want when the workbook is opened. For instance, you could use a very simple macro such as this:

Private Sub Workbook_Open()
    ActiveWindow.Zoom = InputBox("Enter desired workbook Zoom level", "Zoom Factor")
End Sub

This prompts the user, when the workbook is opened, for the desired zoom level. This macro needs to be part of the ThisWorkbook object, so make sure you add it into the proper place in the VBA Editor. The easiest way to do this is to follow these steps:

  1. Press Alt+F11 to display the Visual Basic Editor.
  2. Using the Project window, double-click the ThisWorkbook object. (Make sure you double-click on the ThisWorkbook object associated with the workbook where you want to add the macro.) You'll see a code window for the ThisWorkbook object appear.
  3. Put the above code in the code window.

The major drawback to the macro is that the user is prompted for a zoom level every time the workbook is opened. If James wants a more automatic way, then the macro needs to determine the name of the person opening the workbook. This is done, most reliably, by checking the Windows login name for the person's system:

Private Sub Workbook_Open()
    Dim userName As String

    userName = Environ("Username")
    Select Case LCase(userName)
        Case "tom"
            ActiveWindow.Zoom = 90
        Case "dick"
            ActiveWindow.Zoom = 110
        Case "harry"
            ActiveWindow.Zoom = 100
        Case Else
            ActiveWindow.Zoom = InputBox("Enter desired workbook Zoom level", "Zoom Factor")
    End Select
End Sub

The toughest trick here is to discover what each person's login name is in Windows. It is critical that each Case statement utilize the lowercase version of the person's login name, exactly. You can find out their login name by running this short macro on each system:

Sub GetUserName()
    MsgBox Environ("Username")
End If

Jot down the names, and then put them into the Workbook_Open event handler noted above.

Realize that the macros discussed so far affect the zoom level for only whatever worksheet is active when the workbook is opened. If you want to affect the zoom level for all worksheets in the workbook, then you can modify the macro slightly:

Private Sub Workbook_Open()
    Dim userName As String
    Dim iLevel As Integer
    Dim s As Worksheet

    userName = Environ("Username")
    Select Case LCase(userName)
        Case "tom"
            iLevel = 90
        Case "dick"
            iLevel = 110
        Case "harry"
            iLevel = 100
        Case Else
            iLevel = InputBox("Enter desired workbook Zoom level", "Zoom Factor")
    End Select

    Application.ScreenUpdating = False

    For Each s In Worksheets
        s.Activate
        ActiveWindow.Zoom = iLevel
    Next s

    Application.ScreenUpdating = True
End Sub

This approach works well if you have a relatively small number of users. If you have more users, or the number of users changes often, then you may want to create a version that reads a list of user names from a worksheet. Just set up a worksheet, put the user login names into a column and, to the right of each name, the desired zoom level. Select the names and levels and assign the name UserLevels to the range. You can then change the macro to this:

Private Sub Workbook_Open()
    Dim userName As String
    Dim rUsers As Range
    Dim iLevel As Integer
    Dim s As Worksheet
    Dim c As Range

    Set rUsers = ThisWorkbook.Names("UserLevels").RefersToRange
    userName = Environ("Username")

    iLevel = 0
    For Each c In rUsers.Columns(1).Cells
        If c.Value = userName Then
            iLevel = c.Offset(0, 1).Value
            Exit For
        End If
    Next c

    If iLevel = 0 Then
        iLevel = InputBox("Enter desired workbook Zoom level", "Zoom Factor")
    End If

    Application.ScreenUpdating = False

    For Each s In Worksheets
        s.Activate
        ActiveWindow.Zoom = iLevel
    Next s

    Application.ScreenUpdating = True
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3077) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Word Operates Backwards

What is someone to do when all of a sudden Word starts displaying text from right to left instead of left to right? The ...

Discover More

Using an Input Mask

When you are entering information in a worksheet, it sure would be handy to have a way to "mask" the information being ...

Discover More

Saving in Multiple Locations

Need to save a workbook in more than one location? Here's a handy macro that can save your workbook in lots of different ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More ExcelTips (ribbon)

Specifying a Delimiter when Saving a CSV File in a Macro

You can, within a macro, save a workbook in several different file formats that are understood by Excel. However, you may ...

Discover More

Making a Macro Button Stay Put

Excel allows you to add buttons to your worksheet that can be used to trigger macros. If you don't want those buttons to ...

Discover More

Converting Numbers Into Words

Write out a check and you need to include the digits for the amount of the check and the value of the check written out ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 + 4?

2025-10-25 07:47:59

jamies

The parts, or all of the following script code may be of use -

but note that
Application.ExecuteExcel4Macro("Get.ToolBar(7,""Ribbon"")")

will probably need the setting options to allow the excel4 macro mode, and
acceptance of the security risks associated with that permission.
however the excel4 macros (AFAIK) well remember allow analysis of data being entered into a cell,
rather than what excel considers the entry as a whole was - e.g 2/3/5 being a date to Excel,
and 00045789e-3 or 000457.89 being float numbers rather than text strings



Sub windowfix2016()

' For excel 2016 - Change the window size, range & ribbon status .....
' only for office 2016 but if 2013 also needs dealing with that will be test for version 15
If Application.Version < 16 Then
nn = ""
Else

' This is to be called by the macros that open a subsiduary worksheet
' use a Global setting for all window realignments - this can be set according to the users wishes
' After doing the active .screen .workbook & .worksheet it will then set the ribbon as requested

Dim iRibbon As Integer ' 0 = none, 1 = Menu, 2 = Commands too, 3= Leave as is
Dim iStartX As Integer
Dim iStartY As Integer
Dim iDesiredWidth As Integer
Dim iDesiredHeight As Integer
Dim iviewrange As String
iRibbon = 1 ' 0 = none, 1 = Menu, 2 = Commands too, 3= Leave as is
iStartX = 50 ' Distance from left
iStartY = 25 ' Distance from top
iDesiredWidth = 600
iDesiredHeight = 500
iviewrange = "A1:G35" ' Note the columns are what matters


With Application
.WindowState = xlMaximized
iMaxWidth = Application.Width ' max end is the window end in fullscreen
iMaxHeight = Application.Height
iMaxWidth = iMaxWidth - iStartX ' Adjust window for starting point
iMaxHeight = iMaxHeight - iStartY
If iDesiredWidth > iMaxWidth Then iDesiredWidth = iMaxWidth
If iDesiredHeight > iMaxHeight Then iDesiredHeight = iMaxHeight
.WindowState = xlNormal ' so now set the window
.Top = iStartY
.Left = iStartX
.Width = iDesiredWidth
.Height = iDesiredHeight
End With
' and now fit the selected range into that window
ActiveSheet.Range(iviewrange).Select
ActiveWindow.Zoom = True

' Now for the ribbon setting

If iRibbon = 3 Then
iRibbon = 3 ' do nothing
Else

' In Word:
' ActiveWindow.ToggleRibbon has the same effect as double-clicking on a ribbon tab.
' In Excel: this swaps the state to lose the menu and ribbon, or reinstate it
' RibbonHeight <100 (=73?) seems to mean it is hidden, or in no commands mode
' RibbonHeight >100 (well >73?) seems to mean it is not hidden, and is also showing commands
' (hidden you get full-screen usage, with tabs showing
' Restore sets it to windowed without the menu

Dim iribbonheight As Long
Dim iribbonstate As Long
iribbonstate = Application.ExecuteExcel4Macro("Get.ToolBar(7,""Ribbon"")")
iribbonheight = CommandBars("Ribbon").Controls(1).Height
' So - switch ribbon on/off state
' Off = full screen filename at top and tabs at bottom
' on is ribbon with, or without commands - as determined by the CommanBars.ExecuteMSO MinimizeRibbon
' But Show False hides all the surround of the page and full-window's it.
' need to use the setting for "show tabs" rather than "Autohide" or "Show tabs and Commands"

If iRibbon = 0 Then
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)" ' 0 = no ribbon
Else
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", True)" ' 1 or 2 = show ribbon
End If
ribbonheight = CommandBars("Ribbon").Controls(1).Height
ribbonstate = (CommandBars("Ribbon").Controls(1).Height < 100) ' under 100 means no commands

'Hide Ribbon if it is on the screen in 2010-2016
If ribbonstate = vbFalse And iRibbon = 1 Then CommandBars.ExecuteMso "MinimizeRibbon"
If ribbonstate = vbTrue And iRibbon = 2 Then CommandBars.ExecuteMso "MinimizeRibbon"
' yes - CommandBars.ExecuteMso "MinimizeRibbon seems to toggle minimize to max and back

End If
End If

End Sub


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.