For those who use Phrase to put in writing the occasional letter, you in all probability don’t take into consideration Phrase types too usually. Alternatively, some customers may consider types as a formatting jungle. One of many fundamental causes types confound customers is as a result of there are such a lot of of them and most go unused. The Types pane does a superb job of lowering the variety of types you work together with however ultimately, you may need to delete all unused types from a completed doc. On this article, I’ll present you a VBA process that can take away all unused types within the present doc. Take into account that you possibly can’t delete built-in types in any respect although, so this can be a resolution for paperwork with unused customized types.
SEE: Software program Set up Coverage (TechRepublic Premium)
I’m utilizing Microsoft 365 on a Home windows 10 64-bit system, however you need to use an earlier model. In your comfort, you possibly can obtain the demonstration .docm, .doc and .cls recordsdata. Phrase for the net doesn’t help VBA procedures.
Why do you have to take away unused types in Phrase?
Most of us use only some types in an abnormal doc, however the underlying template incorporates dozens of built-in types. Add personalized types, and you may see issues develop out of hand. There are three good causes you may need to take away a doc’s unused types:
- In a big doc with plenty of customized types that you simply’re not utilizing, you may see a little bit of a efficiency hit. It’s not as large a problem with at this time’s programs loaded with RAM, however eradicating the unused types is an choice.
- It’s a good suggestion to eliminated unused types in a Phrase doc that you simply plan to distribute to lots of people. Doing so will make it tougher for recipients to alter the formatting, which could mess up the complete doc.
- You inherit the upkeep of an older doc that wants some cleanup work.
Determine A reveals the Fast Types gallery for the demonstration doc. Click on the Types group’s dialog launcher to see much more. These are largely built-in types supported by Regular, the underlying template. A couple of are customized types. Most paperwork won’t use most of those types. However this provides you a peek inside types—there are loads of them, and most are built-in, which might’t be eliminated.
Determine A
It doesn’t take lengthy for a doc to turn into overrun with plenty of customized however unused types if you happen to save customized types to the Regular template. On this case, each new doc comes together with loads of fashion baggage. To shortly discern what number of types you might have in use in a Phrase doc, do the next:
- Click on the Types group’s dialog launcher.
- On the backside of the Types pane, click on Choices.
- Within the ensuing dialog, select In Use from the Choose Types In Use dropdown (Determine B).
- Click on OK.
Determine B
Determine C
As you possibly can see in Determine C, the Types pane reveals solely the types in use now—solely seven! Nonetheless, there’s just one customized fashion in use. I’m wondering what number of unused customized types we will take away.
How you can enter the process in Phrase
You possibly can strive deleting types one after the other, however that sounds terrible. You should use Change to delete unused types, however once more, you’d be doing so one after the other. Utilizing both methodology, it’s essential to know which types aren’t getting used. The Phrase VBA process in Itemizing A mimics a exchange activity. I like to recommend that you simply run this process on a replica, simply in case.
Itemizing A
Sub DelUnusedStyles()
'Delete all unused types, apart from built-in types,
'within the present doc.
'You possibly can't delete built-in types.
Dim s As Fashion
For Every s In ActiveDocument.Types
'Solely execute With if present s is not a built-in fashion.
If s.BuiltIn = False Then
With ActiveDocument.Content material.Discover
.ClearFormatting
.Fashion = s.NameLocal
.Execute FindText:="", Format:=True
If .Discovered = False Then s.Delete
Finish With
Finish If
Subsequent
Finish Sub
To enter the process, press Alt + F11 to open the Visible Primary Editor (VBE). Within the Undertaking Explorer to the left, choose ThisDocument and enter the process as proven in Determine D. You possibly can enter the code manually or import the downloadable .cls file. As well as, the macro is within the downloadable .docm, .doc, and .cls recordsdata. For those who enter the code manually, don’t paste from this net web page. As a substitute, copy the code right into a textual content editor after which paste that code into the ThisDocument module. Doing so will take away any phantom net characters which may in any other case trigger errors.
Determine D
If you’re utilizing a ribbon model, you’ll want to save the workbook as a macro-enabled file. For those who’re working within the menu model, you possibly can skip this step.
To run the process, click on the Developer tab after which click on Macros within the Macros group. Within the ensuing dialog, proven in Determine E, choose the DelUnusedStyles process and click on Run. The process cycles via the Types assortment deleting all unused types, apart from the built-in types.
Determine E
Almost definitely, you gained’t need to work via all these steps to run this macro. I like to recommend that you simply add it to the Fast Entry Toolbar or a customized group. For those who need assistance with that, learn How you can add Workplace macros to the QAT toolbar for fast entry.
Keep in mind, you possibly can’t delete the built-in types, however you possibly can scale back the variety of customized types obtainable within the Types pane by altering Beneficial to In Use, as we did earlier. On this case, the Types pane nonetheless shows the identical listing as a result of these types are in use. The process doesn’t let you know what number of had been deleted if any. Within the case of this easy doc, the process might not have deleted a single fashion. You’ll need to save this process for these lengthy and previous paperwork that a number of individuals have labored on earlier than you. Or for all paperwork, if you happen to save all customized types to Regular.
This process or others shut in activity have been round for a very long time. I can’t take credit score for it, however it’s simply adaptable to fit your wants.
How the VBA process works in Phrase
The DelUnusedStyles process is straightforward to know and preserve. It mimics Phrase’s Change function, specifying a mode by title because the discover string and leaving the exchange string clean. In actual fact, you could possibly file a lot of this process and revamp it. You will see that, although, that the file process has loads of pointless code and makes use of specific alternatives, which is inefficient. DelUnusedStyles is succinct and environment friendly.
After declaring the s variable as a Phrase fashion, the For Every assemble cycles via all of the types within the Types assortment. If the Constructed-in property is False, which means the fashion isn’t a built-in fashion, the With block units the required discover properties:
- .ClearFormatting removes any formatting utilized in a earlier discover activity.
- .Fashion is about to the present fashion’s title (s being the Types variable).
- .Execute runs the duty utilizing no textual content within the discover string.
When the present Fashion’s .Discovered property is False, the process deletes it. The process repeats this cycle for each fashion within the present doc.
If you end up utilizing the process usually, add it to Private.xlsb or to the Fast Entry Toolbar (QAT) for fast entry. To study extra about Private.xlsb, learn How you can create a VBA process that closes all open workbooks in Excel.