Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Determining How Many Windows are Open.
by Allen Wyatt
(last updated June 23, 2018)
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3327) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Determining How Many Windows are Open.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Want to run a macro in Excel, but not sure if doing so will tie up your computer? Here's how macro processing really happens.Discover More
When you assign a macro to a shortcut key, you make it easy to run the macro without ever removing your hands from the ...Discover More
Even if you do nothing but record macros, sooner or later you will have a need to edit what you record. Here's how to get ...Discover More
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.