Written by Allen Wyatt (last updated October 17, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
It is sometimes helpful for your macro to know how many Excel workbook windows are open at any given time. For instance, you might want your macro to only run if there is a single window open, or you might even require there to be two windows open. Either way, you need to check how many there are.
You determine the number of open windows by using the Count property of the Windows object. This is done using the following syntax:
X = Windows.Count
After executing the line, X is equal to the number of open windows.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10652) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Determining How Many Windows are Open.
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!
Sometimes it may be helpful for a macro to know exactly where it is being executed. This tip provides a way that you can ...
Discover MoreHaving problems with using macros in a protected workbook? There could be any number of causes (and solutions) as ...
Discover MoreImport a bunch of ZIP Codes into Excel, and you may be surprised that any leading zeroes disappear. Here's a handy little ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments