find and replace

J

Joanne

The purpose of my macro is to insert a space after a comma when the
document originator failed to do so. The problem is that if I run the
macro on the entire document, it will put a space after the comma in
numerics, which is not a good thing. Such as $25, 000.00

Could someone please help me fix this macro so that when it encounters
a comma that is flnaked by numbers, it does not put a space behind the
comma? I've read the help file and tried to utilize it, but to no
avail.

Here is my macro code:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ","
.Replacement.Text = ", "
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll


Here is the way I tried to fix my macro
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ",([! 0-9])"
.Replacement.Text = ", \1"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

BTW, could you explain what the \1 is doing in line 5 of the second
set of code?

Thanks for your help
Joanne
 
D

Dave Lett

Hi Joanne,

You're almost there; you simply didn't include the .MatchWildcards line in
your second routine:

With Selection.Find
.ClearFormatting
.Text = ",([! 0-9])"
With .Replacement
.ClearFormatting
.Text = ", \1"
End With
.MatchWildcards = True
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

For complete information on using Wildcards, have a look at the article
"Finding and replacing characters using wildcards" at
http://word.mvps.org/faqs/general/UsingWildcards.htm

HTH,
Dave
 
Top