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 August 7, 2014)
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.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Want a quick way to convert positive values to negative and vice versa? You can create your own plus/minus button by using a ...Discover More
It is possible to develop macros that update the information in your worksheets automatically. In such instances, you may ...Discover More
When programming macros, variables are used extensively. At some point you might want to exchange the values held by two ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."