Hi: I want to remove the forward slash from a document if and only if it is
preceded by one or more spaces. i.e. “abc/” is OK but “ /” or “ /” or “
/abc”… is not. The following code successfully removes the forward slash
character that is preceded by a single space from a document and replaces it
with a highlighted space. So if there are 2 or more…spaces before the forward
slash, I want it to be removed and replaced with a highlighted space. (I am
fine with all the spaces being removed and simply replacing the entire string
with a single space.) What do I need to do to modify the code to accomplish
such? Any help is greatly appreciated.
'Removes / proceeded by a single space and replaces with a highlighted space
Dim rDcmForwardSlash As Range
Set rDcmForwardSlash = ActiveDocument.Range
With rDcmForwardSlash.Find
.Text = " /"
.Replacement.Highlight = True
.Replacement.Text = " "
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Doug Robbins - Word MVP - 09 Sep 2006 11:45 GMT
See the article "Finding and replacing characters using wildcards" at:
http://www.word.mvps.org/FAQs/General/UsingWildcards.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hi: I want to remove the forward slash from a document if and only if it
> is
[quoted text clipped - 24 lines]
> .Execute Replace:=wdReplaceAll
> End With
Helmut Weber - 09 Sep 2006 12:03 GMT
Hi snsd,
there are many ways to do that.
The following is only the way I am used to:
Sub Test001()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = " {2,}/"
.MatchWildcards = True
While .Execute
rDcm.Text = " /"
rDcm.Characters(1).HighlightColorIndex = wdYellow
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
HTH

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Graham Mayor - 09 Sep 2006 12:51 GMT
Wildcard replace
[ ]@/
with
space
http://www.gmayor.com/replace_using_wildcards.htm
so
With rDcmForwardSlash.Find
.Text = " @/"
.Replacement.Highlight = True
.Replacement.Text = " "
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi: I want to remove the forward slash from a document if and only if
> it is preceded by one or more spaces. i.e. "abc/" is OK but " /" or "
[quoted text clipped - 18 lines]
> .Execute Replace:=wdReplaceAll
> End With
snsd - 09 Sep 2006 13:27 GMT
Thanks guys. Works like a charm. Greatly appreciated.
> Hi: I want to remove the forward slash from a document if and only if it is
> preceded by one or more spaces. i.e. “abc/” is OK but “ /” or “ /” or “
[quoted text clipped - 17 lines]
> .Execute Replace:=wdReplaceAll
> End With