View Single Post
 
Old 09-08-2015, 04:16 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Andrew,

Good catch! I was lazy and copied his test document content into his template and didn't get that result. Copying his code into his text document though and the loop appeared.

Instead of removing it, I would change the code as follows:

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.Collapse wdCollapseEnd
        If oRng.End = ActiveDocument.Range.End - 1 Then Exit Do
    Loop
End With
End Sub
Cyroxote, I didn't think you were making it up. I just didn't see the problem until Andrew pointed it out.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote