Changing the Names of Multiple Styles

by Allen Wyatt
(last updated August 28, 2021)

Normand has documents with up to 25-30 custom styles. The names of these styles start with the letters NB. He would like to rename the styles by changing the NB to NF. Normand knows how to do it one by one, but is looking for a way to batch process the changes.

This type of change is easy to do with a macro. Word makes available, to VBA, the name of each style which can also be change through the macro. Here's an example:

Sub ChangeStyleNames()
    Dim s As Style

    For Each s In ActiveDocument.Styles
        If Left(s, 2) = "NB" Then s = "NF" & Mid(s, 3)
    Next s
End Sub

The macro steps through each style in the document and, if the first two letters are "NB", changes those letters to "NF". Note that the macro only needs to work with individual style objects (denoted by the s variable), and that the NameLocal property doesn't need to be explicitly cited. This is because in the absence of an explicit property, the NameLocal property is the one automatically assumed by VBA.

The macro is very fast to run. In testing on a document with almost 400 styles, it took less than 2 seconds to complete. It checks all styles, both built-in and user-defined.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10120) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Automatic Non-breaking Spaces in Dates

It drives some people crazy to have a date break across two lines. If you find yourself in this mindset, then you'll ...

Discover More

Easily Deploying Customizations

When you create a whole set of customizations for Excel, you may want to share them with others in your office or ...

Discover More

Locking the Background Color

You can spend a lot of time getting the formatting in your worksheets just right. If you want to protect an element of ...

Discover More

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!

More WordTips (ribbon)

How Word Applies Styles

Styles are a great boon for applying styles in a powerfully consistent manner. How Word applies styles, however, depends ...

Discover More

Renaming a Style

Styles are invaluable when it comes to applying consistent formatting in and across documents. If you need to rename a ...

Discover More

Stopping Styles from Changing with Multiple Users

Using styles in your documents can be very helpful when it comes to consistency and ease of formatting. When others open ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six more than 6?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.