![]() |
|
#2
|
||||
|
||||
|
Try something based on:
Code:
Sub ChangeActiveDocument()
Application.ScreenUpdating = False
Dim ArrStlFnd(), ArrStlRep(), i As Long
ArrStlFnd = Array("Heading 1", "Heading 2", "Heading 3", "Main Topic", "Epic Title")
ArrStlRep = Array("Heading 1", "Heading 2", "Heading 3", "Heading 1", "Heading 3")
For i = 0 To UBound(ArrStlFnd)
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Format = True
.Style = ArrStlFnd(i)
.Wrap = wdFindStop
.Execute
End With
Do While .Find.Found
.Style = ArrStlRep(i)
.ParagraphFormat.Reset
.Font.Reset
If .Information(wdWithInTable) = True Then
If .End = .Cells(1).Range.End - 1 Then
.End = .Cells(1).Range.End
.Collapse wdCollapseEnd
If .Information(wdAtEndOfRowMarker) = True Then
.End = .End + 1
End If
End If
End If
.Collapse wdCollapseEnd
If (ActiveDocument.Range.End - .End) < 2 Then Exit Do
.Find.Execute
Loop
End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Infinite loops occurring in find and replace functions in word macro
|
Thefirstfish` | Word VBA | 5 | 04-06-2017 07:18 PM |
| MACRO in infinite loop when it encounters user defined figure label | photoval | Word VBA | 3 | 02-02-2016 08:26 PM |
| Outlook 2013 - caught in an infinite loop on startup | borderfox | Outlook | 0 | 07-26-2015 01:40 PM |
Finding and replacing fonts and styles
|
Adriano | Word VBA | 10 | 03-17-2013 07:08 PM |
| 'Infinite Loop' error with Infopath 2010 | Debbie25 | Misc | 2 | 05-18-2011 08:38 AM |