Search and replace sometimes fails

J

John

The following is called from another procedure. Its
purpose is to colour red everying enclosed by "{}" in a
Word document. Sometimes it works, sometimes it does not,
apparently at random. I can't see why.

Sub AllVariantsRed()
'
' AllVariantsRed Macro
' Macro recorded 27/10/03 by John

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorRed
With Selection.Find
.text = "\{*\}"
.Replacement.text = ""
.Forward = True
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub

I have tried reducing the size of the project in which
this procedure is included. I have tried reducing the
number of levels of procedures calling others. The
computer has plenty of memory.

A number of other procedures involving replace or search
are similarly unreliable.

Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top