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.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Macros are often used to process documents. If part of the processing involves making text selections uppercase, Word ...Discover More
Do you need to copy, within a macro, a range of pages? Because pages can be so fluid in Word, this can be a bit tricky. ...Discover More
The heart of creating powerful programs in VBA is to understand how to create subroutines. These structures allow you to ...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.