Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #15  
Old 02-14-2017, 11:14 AM
slaycock slaycock is offline Normalising styles with +condensed Windows 7 64bit Normalising styles with +condensed Office 2013
Expert
Normalising styles with +condensed
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Normalising styles with +condensed different hyperlink-styles in two superior styles -SLIME- Word 1 04-09-2016 08:51 AM
Normalising styles with +condensed Need some urgent condensed Project knowledge!! Halesowenmum Project 1 10-06-2014 06:18 PM
Normalising styles with +condensed Restricting paragraph styles without restricting character styles Red Pill Word 5 05-25-2012 01:06 PM
Can't Display "Recently Used Styles" in Styles Pane mwildem Word 2 05-23-2012 01:42 PM
Normalising styles with +condensed Quick Styles Set saved but it doesnt appear at the styles list! Pedro77 Word 3 10-15-2011 05:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:28 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft