E
Ed from AZ
I have code which is supposed to find instances of 2 or more spaces
and replace them with one space. It's supposed to work within a set
range, but it keeps going out of the range all the way to the end of
the document. How do I stop it at the end of the range?
Ed
With oRng.Find
.ClearFormatting
.Text = "[! ] {2,}[! ]"
.MatchWildcards = True
While .Execute
Select Case oRng.Characters.First.Text
Case Is = "."
oRng.Text = oRng.Characters.First & " " &
oRng.Characters.Last
Case Is = ":"
oRng.Text = oRng.Characters.First & " " &
oRng.Characters.Last
Case Is = "-"
oRng.Text = oRng.Characters.Last
Case Else
oRng.Text = oRng.Characters.First & " " & oRng.Characters.Last
End Select
oRng.Collapse Direction:=wdCollapseEnd
Wend
End With
and replace them with one space. It's supposed to work within a set
range, but it keeps going out of the range all the way to the end of
the document. How do I stop it at the end of the range?
Ed
With oRng.Find
.ClearFormatting
.Text = "[! ] {2,}[! ]"
.MatchWildcards = True
While .Execute
Select Case oRng.Characters.First.Text
Case Is = "."
oRng.Text = oRng.Characters.First & " " &
oRng.Characters.Last
Case Is = ":"
oRng.Text = oRng.Characters.First & " " &
oRng.Characters.Last
Case Is = "-"
oRng.Text = oRng.Characters.Last
Case Else
oRng.Text = oRng.Characters.First & " " & oRng.Characters.Last
End Select
oRng.Collapse Direction:=wdCollapseEnd
Wend
End With