![]() |
#15
|
|||
|
|||
![]() Quote:
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 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. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
-SLIME- | Word | 1 | 04-09-2016 08:51 AM |
![]() |
Halesowenmum | Project | 1 | 10-06-2014 06:18 PM |
![]() |
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 |
![]() |
Pedro77 | Word | 3 | 10-15-2011 05:17 AM |