Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-21-2018, 03:46 PM
macropod's Avatar
macropod macropod is offline Infinite Loop when Finding Styles Windows 7 64bit Infinite Loop when Finding Styles Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,523
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Infinite Loop when Finding Styles 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
Infinite Loop when Finding Styles 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:29 PM.


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