bobby23
08-19-2013, 01:06 AM
Hello
I've been working on this macro for some time and found that it sometimes falls into infinite loop. Could someone help me out with a suggestion.
Her's the code:
Sub replacing ()
Dim rngStory As Word.Range
Application.ScreenUpdating = False
For Each rngStory In ActiveDocument.StoryRanges
Do
With rngStory.Find
.ClearFormatting
.Highlight = True
.Wrap = Word.WdFindWrap.wdFindStop
.Execute
While .Found = True
If rngStory.HighlightColorIndex = wdRed Then
rngStory.Font.ColorIndex = wdRed
End If
rngStory.Collapse wdCollapseEnd
.Execute
Wend
End With
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
Application.ScreenUpdating = True
End Sub
I've been working on this macro for some time and found that it sometimes falls into infinite loop. Could someone help me out with a suggestion.
Her's the code:
Sub replacing ()
Dim rngStory As Word.Range
Application.ScreenUpdating = False
For Each rngStory In ActiveDocument.StoryRanges
Do
With rngStory.Find
.ClearFormatting
.Highlight = True
.Wrap = Word.WdFindWrap.wdFindStop
.Execute
While .Found = True
If rngStory.HighlightColorIndex = wdRed Then
rngStory.Font.ColorIndex = wdRed
End If
rngStory.Collapse wdCollapseEnd
.Execute
Wend
End With
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
Application.ScreenUpdating = True
End Sub