How can I automatically remove unused styles from a Word doc?
March 17, 2005 6:02 AM Subscribe
Some of my MS Word docs (Microsoft Word 2003, Windows XP) have been through many hands and have many styles defined. Lots of these styles are garbage. Other than doing it manually (stepping through all of the styles one by one, checking whether each style is in use, and then deleting the styles I don't need), is there a way to remove all styles that are not used in a document?
(and make sure you backup anything you run those macros on)
posted by null terminated at 6:36 AM on March 17, 2005
posted by null terminated at 6:36 AM on March 17, 2005
Try this: Select the entire document except for the very last paragraph mark. Copy and paste into a new document.
Word "invests" document-level formatting (which, I believe, would include redundant styles) in that final paragraph mark, and this trick cures a range of maladies afflicting Word docs. I haven't tried using this trick to solve this particular problem, but give it a shot.
posted by adamrice at 7:27 AM on March 17, 2005
Word "invests" document-level formatting (which, I believe, would include redundant styles) in that final paragraph mark, and this trick cures a range of maladies afflicting Word docs. I haven't tried using this trick to solve this particular problem, but give it a shot.
posted by adamrice at 7:27 AM on March 17, 2005
When I am faced with the same situation as pracowity, here's what I do: Highlight all the text in the document by clicking [Control] and [A] keys. Then click [Control] and [C] keys to copy. Then open a new word document, be sure to use blank document, not template. Place the cursor at the top of the page in the new document pane and click. Now go up to the tool bar at the top of the document and click on Edit. In the Edit drop-down menu you should see Paste Special. Click on Paste Special and you will be presented with a series of choices of document styles. Click on Unformatted Text. Voila, you have a plain text document to which you can apply any style that you want!
posted by Lynsey at 10:20 AM on March 17, 2005
posted by Lynsey at 10:20 AM on March 17, 2005
There are a couple of options you can use to help manage the pain of styles in Word docs... Open the "Styles and Formatting" sidebar, and select "Show styles in use" (drop-down list at the bottom).
Once you have it restricted to showing only what is currently in use, go back to that drop-down list and select "Custom" to open the "Format Settings" pop-up.
Next click the "Styles" button, to open the list of available styles. Select "user defined styles" to show just the non-standard styles in use, ignoring MS-defined things like Heading 1, etc. You can delete any here that are not listed as being in use in the sidebar (unfortunately you need to close this window to scroll the sidebar, so this is a multi-step process. This is a pain, I know, but this is Microsoft.)
The "Organizer" button in bottom left of the Styles pop-up will go to the Organizer window. The Organizer window shows the styles in use, both in the current document and in the Normal.dot document template. You can move often-used styles into Normal here, or kill all styles in the document and just keep whats in Normal.
The other trick to remember is that styles are nested: Bold, then Bold + Indented, then Bold + Indented + Font Size... If you delete the "Bold" style, you also delete the nested variants (you might be creating a new Indented + Font Size style though).
Finally, to clear junk out, the only other option you have is to get the sidebar to show all styles, then manually click on each one to see how many instances of it there are. If there are no instances of a particular style or it's nested variants, delete the style.
PS: The "Remove Hidden Data" tool will kill unused styles (I think) but it has the unfortunate side effect of inserting an auto-warning about hidden data every time the file is subsequently opened (even if opened, edited, and saved as a new document). There is now way I am aware of to remove this warning, which is a pain in the ass.
posted by caution live frogs at 12:09 PM on March 17, 2005 [1 favorite]
Once you have it restricted to showing only what is currently in use, go back to that drop-down list and select "Custom" to open the "Format Settings" pop-up.
Next click the "Styles" button, to open the list of available styles. Select "user defined styles" to show just the non-standard styles in use, ignoring MS-defined things like Heading 1, etc. You can delete any here that are not listed as being in use in the sidebar (unfortunately you need to close this window to scroll the sidebar, so this is a multi-step process. This is a pain, I know, but this is Microsoft.)
The "Organizer" button in bottom left of the Styles pop-up will go to the Organizer window. The Organizer window shows the styles in use, both in the current document and in the Normal.dot document template. You can move often-used styles into Normal here, or kill all styles in the document and just keep whats in Normal.
The other trick to remember is that styles are nested: Bold, then Bold + Indented, then Bold + Indented + Font Size... If you delete the "Bold" style, you also delete the nested variants (you might be creating a new Indented + Font Size style though).
Finally, to clear junk out, the only other option you have is to get the sidebar to show all styles, then manually click on each one to see how many instances of it there are. If there are no instances of a particular style or it's nested variants, delete the style.
PS: The "Remove Hidden Data" tool will kill unused styles (I think) but it has the unfortunate side effect of inserting an auto-warning about hidden data every time the file is subsequently opened (even if opened, edited, and saved as a new document). There is now way I am aware of to remove this warning, which is a pain in the ass.
posted by caution live frogs at 12:09 PM on March 17, 2005 [1 favorite]
Response by poster: Well, the last thing I want to do with 200+ pages of complicated technical documentation is to lose all of the formatting and start fresh.
The macro sounds best but it returned a VB error when I tried it. Copying and pasting everything but the last paragraph mark also didn't work. (And the docs I'm worried about are big.) The Microsoft recommendation (to save as RTF, then open as text, then manually delete each unwanted style) is worse than just deleting them through the Word interface.
Maybe this: use find and replace on all styles that I want, so that every paragraph of style "weasels" would get a special string like {++weasels++}. Then save as text to get rid of all styles, then open it as a regular doc again, create or import desired styles, then use find and replace to return make all labeled paragraphs to the correct styles, and then another find and replace to delete all labels like {++weasels++}.
But that still wipes out graphics and tables and so on, right?
Hmm.
posted by pracowity at 1:18 PM on March 17, 2005
The macro sounds best but it returned a VB error when I tried it. Copying and pasting everything but the last paragraph mark also didn't work. (And the docs I'm worried about are big.) The Microsoft recommendation (to save as RTF, then open as text, then manually delete each unwanted style) is worse than just deleting them through the Word interface.
Maybe this: use find and replace on all styles that I want, so that every paragraph of style "weasels" would get a special string like {++weasels++}. Then save as text to get rid of all styles, then open it as a regular doc again, create or import desired styles, then use find and replace to return make all labeled paragraphs to the correct styles, and then another find and replace to delete all labels like {++weasels++}.
But that still wipes out graphics and tables and so on, right?
Hmm.
posted by pracowity at 1:18 PM on March 17, 2005
Hmm indeed. One trick I've used on extremely messed-up Word documents is this:
Export to HTML. Open HTML in BBEdit. Remove all styling information, including class attributed in tags (this can go pretty quickly with a little GREPping). Reimport into Word.
If you've been a good boy and set up header styles with the right levels and what not, you'll still have a relatively intact document structure. You can then start styling from scratch.
I admit this is not a desirable option, and is likely more work than just biting the bullet and deleting the styles inside Word.
posted by adamrice at 2:14 PM on March 17, 2005
Export to HTML. Open HTML in BBEdit. Remove all styling information, including class attributed in tags (this can go pretty quickly with a little GREPping). Reimport into Word.
If you've been a good boy and set up header styles with the right levels and what not, you'll still have a relatively intact document structure. You can then start styling from scratch.
I admit this is not a desirable option, and is likely more work than just biting the bullet and deleting the styles inside Word.
posted by adamrice at 2:14 PM on March 17, 2005
« Older Why is mint the premier flavour for dental hygiene... | What to write in people's birthday cards? Newer »
This thread is closed to new comments.
MS has a page on the issue as well, here.
posted by null terminated at 6:35 AM on March 17, 2005