Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

find and replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joanne - 28 Feb 2005 13:55 GMT
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
Dave Lett - 28 Feb 2005 14:37 GMT
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

> 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
[quoted text clipped - 33 lines]
> Thanks for your help
> Joanne

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.