Quote:
Your document has far more going on than just 'condensed' Styles; in fact, it has about 250 custom Styles with micro-variations on the base styles. The simplest way of cleaning up this mess is to:
1. Create a new 'base' document containing just the Styles you want to use;
2. Save the existing document in RTF format
3. Open the document in WordPad, make an edit somewhere, then re-save & close.
4. Re-open the edited RTF document in Word and copy and paste its content into the new 'base' document as formatted text;
5. Re-apply the required Styles.
|
I considered the above but 5 made me baulk. Its exactly what I'm trying to avoid.
After some headscratching I came up with the following code
Code:
Sub ConsolidateStyleVariations()
Dim myStyle As Style
Dim myRange As Range
Dim myChar As Range
Dim myPage As Long
Application.ScreenUpdating = False
myPage = 0
For Each myChar In ActiveDocument.StoryRanges(wdMainTextStory).Characters
Set myStyle = myChar.Style
If myPage + 5 < myChar.Information(wdActiveEndPageNumber) Then
DoEvents
myPage = myPage + 5
End If
If myChar.Fields.Count = 0 Then
myChar.Font.Spacing = 0
myChar.Font.Scaling = 100
myChar.Font.Name = myStyle.Font.Name
If Not myChar.Font.Position = 0 Then
If myChar.Font.Position > 0 Then
myChar.Font.Position = 0
myChar.Font.Superscript = True
End If
If myChar.Font.Position < 0 Then
myChar.Font.Position = 0
myChar.Font.Subscript = True
End If
End If
If myStyle.Type = wdStyleTypeParagraph Then
myChar.ParagraphFormat.FirstLineIndent = myStyle.ParagraphFormat.FirstLineIndent
myChar.ParagraphFormat.LeftIndent = myStyle.ParagraphFormat.LeftIndent
End If
End If
Next
Application.ScreenUpdating = True
End Sub
This works for me because
a. I dont have any styles in my document with changed spacing,position or scaling
b. There are very very few occasions where firstline and left indents differ from the style so I'm prepared to take the hit.
There were a couple of issues
• The fields statement doesn't capture drawing boxes. WHen I checked I only had 4 such items, 3 of which did not convert to inline shape. So when the macro fell over I just set it to continue at the next statement
• It takes a loong time to run, hence the inclusion of do events
• It took 13 hours to run before I added the screen updating commands
The code works because for dynamically created styles (which was creating the issue) if you reset those style to remove the items after the + then this allows word to obligingly remove the dynamic style.
Any comments on adding code to trap drawing boxes or make it more robust/faster would be most welcome.
For now I'm a lot happier as I have a document that is editable (I don't have to wait 5-10 seconds for the document to update every time I make an edit and it is a programmatic solution so can be added to the suite of 'Triage' macros I'm assembling.