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.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
You may need to determine the numeric value of a character in a macro. You can do that using the Asc function, described ...Discover More
While your macro is processing the text in your document, you may need a way to determine the current page number where ...Discover More
Bookmarks can be very handy in a document. Word provides a VBA command you can use to easily select any of those bookmarks.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.