Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. 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 Styles are Available.
by Allen Wyatt
(last updated August 2, 2014)
You can determine the number of styles available in a document (when creating a VBA macro) by using the Count property with the Styles object. This is done using the following syntax:
x = ActiveDocument.Styles.Count
where x is the variable you can then use in other VBA macro lines. Note that this function indicates how many have been defined, not how many of those are actually in use. This means that built-in styles are also counted. If you want to exclude built-in styles, you can do an actual iterative count of the styles in this manner:
x = 0 For Each objStyle in ActiveDocument.Styles If Not objStyle.BuiltIn Then x = x + 1 Next objStyle
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13190) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Determining How Many Styles are Available.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
Creating macros can help extend what you can do in Word. If you work with macros, you know that creating macros from ...Discover More
Want to pull a string apart in a macro? It's easy using the string functions introduced in this tip.Discover More
Want to give your macros a different name than they currently use? It's easy to do using the VBA Editor as described here.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.