Something for the toolbox (excuse the long code-listing!):
I often have to clean up docs that are (supposed to be) using styles.
Two things make that a difficult task:
Formatting done “by hand” is difficult to distinguish from formatting done by using styles.
Selectively returning some formatting properties (font, size, shading, space before …) to their default values is hard to do.
If you set all paragraph styles to look like the “Normal” style (wdStyleNormal; “Standard” in german Word), and all character styles to look like the Default Paragraph Style, then all manual formatting will be obnoxiously visible
(… this is also great to show authors the “errors of their ways”
).
The macro will produce a new document with such “empty” styles.
Running the following macro on a document formatted with styles will make it look like a plain text file; copying the contents into an old version — or copying the styles (from the template or from an old version) to the document — will make the formatting instantly reappear.
You can also use this macro to selectively remove manual formatting:
– run the macro,
– select all text,
– set the formatting of some property (font, underline, borders, indent …) to the default value of the “Normal” style,
– save the doc (important! … Word does some cleaning up when saving)
– copy back the styles.
Sub NewDocEmptyStyles() ' (Save the new file before copying back the styles!) Dim myStyle As Style Dim DlgSaveAs As Dialog Set DlgSaveAs = Dialogs(wdDialogFileSaveAs) OldFile = ActiveDocument.Name Documents.Add NewTemplate:=False, DocumentType:=0 NewFile = ActiveDocument.Name For Each myStyle In Documents(OldFile).Styles If (myStyle.InUse = True And myStyle.BuiltIn = False) Then If myStyle.Type = wdStyleTypeParagraph Then If myStyle Documents(OldFile).Styles(wdStyleNormal) Then Documents(NewFile).Styles.Add Name:=myStyle.NameLocal, Type:=wdStyleTypeParagraph Documents(NewFile).Styles(myStyle).BaseStyle = wdStyleNormal End If Else If myStyle Documents(OldFile).Styles(wdStyleDefaultParagraphFont) Then Documents(NewFile).Styles.Add Name:=myStyle.NameLocal, Type:=wdStyleTypeCharacter Documents(NewFile).Styles(myStyle).BaseStyle = wdStyleDefaultParagraphFont End If End If End If Next myStyle Documents(OldFile).Select Selection.WholeStory Selection.Copy Documents(NewFile).Activate Selection.Paste For Each myStyle In Documents(NewFile).Styles If (myStyle.InUse = True And myStyle.BuiltIn = True) Then If myStyle.Type = wdStyleTypeParagraph Then If myStyle Documents(NewFile).Styles(wdStyleNormal) Then RememberOutlineLevel = myStyle.ParagraphFormat.OutlineLevel myStyle.BaseStyle = Documents(NewFile).Styles(wdStyleNormal) myStyle.Font = Documents(NewFile).Styles(wdStyleNormal).Font myStyle.ParagraphFormat = Documents(NewFile).Styles(wdStyleNormal).ParagraphFormat myStyle.ParagraphFormat.OutlineLevel = RememberOutlineLevel End If End If End If Next myStyle Documents(NewFile).Activate DlgSaveAs.Show End Sub