View Single Post
 
Old 09-07-2015, 07:34 PM
Guessed's Avatar
Guessed Guessed is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

In the sample doc you provided, the final return in the document is highlighted so the loop is repeating there. If you remove that 'invisible' highlight then the code loop ends as expected.

For the purposes of discovering where the oRng was located during the loop, I added a line to your code so I could see the range.
Code:
Private Sub DoColorChange(SearchColor As Long, ReplaceColor As Long)

Dim oDoc As Document
Dim oRng As Range

Set oDoc = ActiveDocument
Set oRng = oDoc.Range

With oRng.Find
    .Highlight = True
    .Wrap = wdFindStop
    Do While oRng.Find.Execute
        If oRng.HighlightColorIndex = SearchColor Then
           oRng.HighlightColorIndex = ReplaceColor
        End If
        oRng.Select
        oRng.Collapse 0
    Loop
End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote