Deleting Unused Styles
August 25, 2004 – 12:00 pmI frequently edit books that are compilations of articles by various authors. Some know how to use Word pretty well; others don’t have a clue. Those in the latter category either don’t use paragraph styles or create styles that aren’t needed. After I’ve fixed and consistently applied the styles I need, I like to get rid of the other unused styles the authors have created. The following macro seems to do the job quite well. Maybe you’ll find it useful:
Sub DeleteUnusedStyles()
‘Courtesy of the Editorium
‘www.editorium.com
For Each sty In ActiveDocument.Styles
If sty.BuiltIn = False Then
If sty.InUse = False Then
sty.Delete
Else
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(sty)
With Selection.Find
.Text = “”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = False Then sty.Delete
End If
End If
Next sty
Selection.HomeKey Unit:=wdStory
End Sub
If you don’t know how to use such macros, you can learn how here:
http://lists.topica.com/lists/editorium/read/message.html?mid=17069228 55
You’d think the macro could be a lot shorter:
For Each sty In ActiveDocument.Styles
If sty.BuiltIn = False Then ‘Ignore built-in styles
If sty.InUse = False Then sty.Delete
End If
Next sty
But Microsoft Word, ever uncooperative, considers any style that has *ever* been used in a document to be “in use,” even if the text formatted by that style has long since been deleted. That means a style can be “in use” even if it’s not applied to text anywhere in the document. So, to see if a style is *really* in use, we have to search for text using that style. If no such text is found, then we know that the style really isn’t in use and can be deleted.
Note that the macro completely ignores Word’s built-in styles, since these *can’t* be deleted.
_________________________________________
READERS WRITE
After reading last week’s article on pasting tracked revisions, Hilary Powers responded to the last paragraph in the article, which read, “But maybe, just maybe, it’s a feature, giving you a choice about whether or not to copy and paste revisions. But if that’s true, why not copy revisions when tracking is on, and *not* copy revisions when tracking is off? That would be more logical. Shoot, maybe it is a bug. If so, now you know how to squash it.”
Hilary wrote:
It’s a feature. Lots of times I’m working along, and I want to pull something from the main document, which has tracking active, to the style sheet–and I want the final version of whatever-it-is, not any changes I may have made in it. That wouldn’t be feasible with the apparently logical system. Keeping only the final version is the more likely choice, so it makes sense to have to do something to keep the tracking.
But it’s a feature only in Word 2000+; in Word 97, there’s a genuine bug: you can’t copy tracking AT ALL. If you want to reproduce a passage with tracking intact, you have to bookmark it, then use Insert, File, Range (bookmark name) to put the bookmarked passage into a file that has tracking turned off. (If you want the whole file, you can simply Insert it without the Range bit.)
————————
Several readers responded to my answer to Wallace Sagendorph’s superscript problem in last week’s newsletter, including Mary Eberle, Eric Fletcher, Shirley S. Ricks, and Iwan Thomas. Eric Fletcher wrote:
I bet I won’t be the only one to let you know about a much easier method to solve Wallace Sagendorph’s superscript problem!
I would just change one instance manually, then select and copy it. Then, in the F&R dialog, put “m3″ in the Find what and “^c” in the Replace with. The caret c replaces each instance found with the content of the clipboard.
Of course, your two-step method works for the general case but I’d be a little hesitant to use it unless I was pretty sure the manuscript didn’t include other constructions that would get messed up. For example, H2O would end up with a superscript 2 with your wildcard method. I once discovered (luckily just before press!) that the 2 in all instances of “V2 rocket” had inadvertently been changed to a superscript because of an earlier fix to km2.
I really like the “Highlight all items” feature of Word’s Find dialog as a tool to easily check the total number of items about to be changed. If it looks a bit too high or I’m not sure, I tick it to cause all found items to be highlighted, drop out of the dialog, copy and then paste into a new Word document. This gives me a list of all found items that is easy to sort or review before committing to the replace. We’ve done several jobs where URLs and email addresses are sprinkled throughout the ms. I tag them with “URL text” character styles (displayed in purple during editing). Not only is it easier to see this way, but the “highlight all/copy/paste to new doc” procedure gives me a sortable list of all such items–always very handy for confirming currency of such items. I also use a similar method for pulling all citations for easier checking.
Many thanks to Hilary, Mary, Eric, Shirley, and Iwan for their excellent tips and comments.
_____________________________________________________
THE FINE PRINT
Editorium Update (ISSN 1534-1283) is published by:
The EDITORIUM, LLC
Microsoft Word Add-Ins for Publishing Professionals
http://www.editorium.com
Copyright © 2008 by the Editorium. All rights reserved. Editorium Update and Editorium are trademarks of the Editorium.
You may forward copies of Editorium Update to yourself and others (but not charge for it) and print or store it for your own use. Any other broadcast, publication, retransmission, copying, or storage, without written permission from the Editorium, is prohibited. Send reprint requests to reprints [at symbol] editorium.com
Editorium Update is provided for informational purposes only and without a warranty of any kind, either express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, and freedom from infringement. The user assumes the entire risk as to the accuracy and use of this document.
The Editorium is not affiliated with Microsoft Corporation.
_____________________________________________________
HOW TO SUBSCRIBE OR UNSUBSCRIBE
To subscribe, send a blank email message to editorium-subscribe [at symbol] topica.com.
To unsubscribe, send a blank email message to editorium-unsubscribe [at symbol] topica.com.
We do not sell, rent, or give our subscriber list to anyone.
____________________________________________________
You must be logged in to post a comment.