Find and replace condition
I want to apply a condition to the replacement.
I want "ea" to be replaced by "2" only when "ea " is not the first or last letters of the word that contains it.
1. How do I apply this condition?
2. How do I get the find and replace to stop when the end of document is reached?
Note: In Braille, the code for "ea" is "2" in a word document.
Help would be greatly appreciated.
Norman
Sub FindAndReplaceEAwith2()
'
' Find and Replace "ea" with "2" Macro
' Macro recorded 31/7/15 by NG
'
On Error GoTo StopMacro
Set oRng = ActiveDocument.Range
oRng.HighlightColorIndex = wdNoHighlight
oRng.Find.ClearFormatting
oRng.Find.Replacement.ClearFormatting
oRng.Find.Replacement.Highlight = True
For i = 1 To 20
With oRng.Find
.Text = "ea"
.Replacement.Text = "2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oRng.Find.Execute Replace:=wdReplaceOne
MsgBox (oRng.Characters.First.Previous)
Next i
StopMacro:
Stop
End Sub
|