Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Determining How Many Windows are Open.
by Allen Wyatt
(last updated April 23, 2016)
It is sometimes helpful for your macro to know how many document 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.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10099) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Determining How Many Windows are Open.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Need to process a document, paragraph by paragraph, in a macro? It's easy to do once you understand that Word's object ...Discover More
When you distribute documents to other people, you may want those documents to have associated macros that the reader can ...Discover More
ScreenTips can appear with or without shortcut keys displayed in them. Here's how to control whether they appear or not.Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.