delete duplicate commas

G

Guest

how do I eliminate all commas except one:
the,,,quick,brown..fox...jumps,over,the.....lazy,dog,

this doesn't work:
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:=",,", Forward:=True, _
Format:=True) = True
With Selection.Find
.Text = ",,"
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
End With


thanks,,,,
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?bWFjcm9BZGRpY3Q=?=,
how do I eliminate all commas except one:
the,,,quick,brown..fox...jumps,over,the.....lazy,dog,
HOW doesn't it work. What kind of result are you getting?
And, which version of Word?

right off hand, I'd say you don't need the Do loop, just
Selection.Find with the Replace All. Executing twice (the
first time without specifying replacement text) is probably
driving Word bananas.
this doesn't work:
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:=",,", Forward:=True, _
Format:=True) = True
With Selection.Find
.Text = ",,"
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
End With

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
G

Graham Mayor

See http://www.gmayor.com/replace_using_wildcards.htm

Replace
,{1,}
with
,

or by macro

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ",{1,}"
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceAll
 

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