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 / September 2006

Tip: Looking for answers? Try searching our database.

Removing specific characters when preceded by one or more spaces

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
snsd - 09 Sep 2006 09:59 GMT
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

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.