If you use Word to write a letter from time to time, you probably don’t think about Word styles too often. On the other hand, some users may think of styles as jungle formatting. One of the main reasons styles confuse consumers is that there are so many of them and most remain unused. The Styles screen does a good job of reducing the number of styles you interact with, but you may end up wanting to delete all unused styles from a finished document. In this article I will show you a VBA procedure that will remove all unused styles in the current document. Note that you can’t delete embedded styles at all, so this is a solution for documents with unused custom styles.

LOOK: Software installation policy (TechRepublic Premium)

I’m using Microsoft 365 on Windows 10 64-bit system, but you can use an earlier version. For your convenience, you can download the demo .docm, .doc and .cls files. Word for the Web does not support VBA procedures.

Why should you remove unused styles in Word?

Most of us use only a few styles in a plain document, but the basic template contains dozens of built-in styles. Add custom styles and you can see things grow out of control. There are three good reasons why you might want to remove unused document styles:

  • In a large document with many custom styles that you don’t use, you can see slightly higher performance. This is not such a big problem with today’s RAM-loaded systems, but removing unused styles is an option.
  • It’s a good idea to remove unused styles in a Word document that you plan to distribute to many people. This will make it more difficult for recipients to change the formatting, which can confuse the entire document.
  • You inherit the maintenance of an older document that needs cleaning work.

Figure A shows the gallery of quick styles for the demo document. Click the Home bar of the Styles group dialog box to see more. These are mostly built-in styles supported by Normal, the main template. Some are custom styles. Most documents will not use most of these styles. But this allows you to peek inside the styles – there are many and most are built-in that cannot be removed.

Figure A

Many styles are available, but are not used in Word documents.
Many styles are available, but are not used in Word documents.

It doesn’t take long for a document to be full of many custom but unused styles if you save custom styles in the Normal template. In this case, each new document comes with a lot of stylish luggage. To quickly find out how many styles you have in use in a Word document, do the following:

  1. Click the Styles group dialog box launcher.
  2. At the bottom of the Styles panel, click Options.
  3. In the resulting dialog, select In Use from the Select Uses Styles drop-down menu (Figure B).
  4. Click OK.

Figure B

Show only the styles used in a Word document.
Show only the styles used in a Word document.

Figure C

The Word Styles screen shows fewer styles now.
The Word Styles screen shows fewer styles now.

As you can see in Figure C, the Styles panel shows only the styles currently in use – only seven! However, there is only one custom style that is used. I wonder how many unused custom styles we can remove.

How to enter the procedure in Word

You can try deleting styles one by one, but that sounds awful. You can use Replace to delete unused styles, but you will do it again one by one. Using each of the two methods, you need to know which styles are not used. The procedure of Word VBA in List A mimics a replacement task. I recommend that you perform this procedure on a copy, just in case.

List A

Sub DelUnusedStyles()
'Delete all unused styles, except for built-in styles,
'in the current document.
'You can't delete built-in styles.
Dim s As Style
For Each s In ActiveDocument.Styles
'Only execute With if current s isn't a built-in style.
If s.BuiltIn = False Then
With ActiveDocument.Content.Find
.Style = s.NameLocal
.Execute FindText:="", Format:=True
If .Found = False Then s.Delete
End With
End If
End Sub

To enter the procedure, press Alt + F11 to open the Visual Basic (VBE) editor. In Project Explorer on the left, select ThisDocument and enter the procedure as shown in Figure D. You can enter the code manually or import the .cls file for download. The macro is also in the .docm, .doc, and .cls files for download. If you enter the code manually, do not paste from this web page. Instead, copy the code in a text editor and then paste it into the ThisDocument module. This will remove any phantom web characters that might otherwise cause errors.

Figure D

Enter the procedure in the ThisDocument module for the current document.
Enter the procedure in the ThisDocument module for the current document.

If you’re using a ribbon version, be sure to save the workbook as a macro-enabled file. If you are working in the menu version, you can skip this step.

To start the procedure, click the Developer tab, and then click Macros in the Macros group. In the Get dialogs window shown in Figure E, select the DelUnusedStyles procedure and click Run. The procedure goes through the collection of styles, deleting all unused styles except the built-in styles.

Figure E

Start DelUnusedStyles
Start DelUnusedStyles.

You probably won’t want to go through all these steps to run this macro. I recommend adding it to the Quick Access Toolbar or Custom Group. If you need help with this, read How to add Office macros to the QAT Quick Access Toolbar.

Remember that you can’t delete built-in styles, but you can reduce the number of custom styles available in the Styles panel by changing Recommended to Used, as we did earlier. In this case, the Styles panel still displays the same list as these styles are used. The procedure does not tell you how many have been deleted, if any. In the case of this simple document, the procedure may not have deleted any styles. You will want to keep this procedure for those long and old documents that several people have worked on before you. Or for all documents, if you keep all custom styles in Normal.

This procedure or other related tasks have existed for a long time. I can’t take credit for it, but it’s easily adaptable to suit your needs.

How the VBA procedure works in Word

The DelUnusedStyles procedure is easy to understand and maintain. It mimics the Word override feature by specifying a style by name as a find string and leaving the replacement string blank. In fact, you can save a lot of this procedure and rework it. However, you will find that the write procedure has a lot of unnecessary code and uses explicit selections, which is ineffective. DelUnusedStyles is short and effective.

After declaring the variable s as a Word style, the For Every construction goes through all the styles in the Styles collection. If the Built-in property is False, which means that the style is not a built-in style, the With block sets the necessary properties to find:

  • .ClearFormatting removes any formatting used in a previous find task.
  • .Style is set to the name of the current style (s is the Styles variable).
  • .Execute performs the task without text in the find string.

When the property of the current style is False, the procedure deletes it. The procedure repeats this cycle for each style in the current document.

If you find that you use the procedure frequently, add it to Personal.xlsb or to the Quick Access Toolbar (QAT). To learn more about Personal.xlsb, read How to create a VBA procedure that closes all open workbooks in Excel.

How to delete unused styles using VBA in Word

Previous articleLeidos Holdings’ IT hiring activity increased by 11.0% in March 2022.
Next articleUSPS promises more serious price increases, even when revenues grow by nearly $ 1 billion