Controlling Window Size when Opening Additional Workbooks

Written by Allen Wyatt (last updated July 22, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

If Steven has a workbook open and maximized, and then he opens one or more additional workbooks, the additional workbooks look maximized but aren't really. The left, bottom, and right sides of these additional workbooks are at the edges of the screen, but the tops cascade downward, like index cards offset from each other. To Steve, it would be much better if the additional workbooks opened either as a smaller portion of the window or as fully maximized so that he could then "restore" the windows to a smaller size. He wonders if there is some setting that controls the window size for these additional workbooks when they are opened.

You can rather easily affect what happens with a workbook window through the use of macros. The normal place to do this would be in the Workbook_Open macro, which is an event handler in the ThisWorkbook object. Here's a very simple version that would simply make sure that the window is maximized:

Public Sub WorkBook_Open()
    Application.WindowState = xlMaximized
End Sub

You can then, if you want, manually adjust the size of the maximized window.

Of course, you could also "build out" the macro so that it manipulates the window in other ways. For instance, the following is a macro that will determine the maximum screen size of the monitor on which the workbook is opening, and then it adjusts the window size to occupy 72% of the screen width and 96% of the screen height.

Public Sub WorkBook_Open()
    Dim iMaxWidth As Integer    'Screen width (pixels)
    Dim iMaxHeight As Integer   'Screen height (pixels)
    Dim sngStartX As Single     'Upper-left corner of desired window
    Dim sngStartY As Single     'Upper-left corner of desired window
    Dim sngWidth As Single      'Width of desired window
    Dim sngHeight As Single     'Height of desired window

    'Specifications for final window size
    sngStartX = 0.14   'Fraction of screen width from left edge
    sngStartY = 0.02   'Fraction of screen height from top
    sngWidth = 0.72    'Fraction of screen width desired
    sngHeight = 0.96   'Fraction of screen height desired

    With Application
        'Maximize screen in order to grab maximum width and height
        .WindowState = xlMaximized
        iMaxWidth = .Width
        iMaxHeight = .Height
        .WindowState = xlNormal

        'Set final window position and size
        .Top = iMaxHeight * sngStartY
        .Left = iMaxWidth * sngStartX
        .Width = sngWidth * iMaxWidth
        .Height = sngHeight * iMaxHeight
    End With
End Sub

You can, of course, adjust the settings in the two variables (sngWidth and sngHeight) to pick a different final screen size. You could also adjust the settings in the sngStartX and sngStartY variables to specify the position for the upper-left corner of the final window.

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

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

Applying Table Formats

Want to make short work of formatting a large data table? You can use the AutoFormat feature of Excel to apply all sorts ...

Discover More

Getting Rid of Hyperlinks in Footnotes

When you add hyperlinks to a document, Word makes them active, meaning you can click them to open the target of the ...

Discover More

Returning Blanks with VLOOKUP

Normally the VLOOKUP function returns a value, and if it can't return a value it returns a zero. Here's how you can use ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Deriving an Absolute Value in a Macro

Need to figure out an absolute value within your macro code? It's easy to do using the Abs function, described in this tip.

Discover More

Testing if a Workbook is Open

Your macros can easily open and manipulate other Excel workbooks. If a workbook you are trying to use is already in use ...

Discover More

Copying Worksheets in a Macro

Copying worksheets (one or many) is easy to do manually. What is not well known is that it is even easy to make the ...

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 six minus 4?

2023-07-22 11:47:33

J. Woolley

For more on this subject, see https://excelribbon.tips.net/T010091_Remembering_Workbook_Position_and_Size.html


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.