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 2006

Tip: Looking for answers? Try searching our database.

deleting text after certain string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
julian_m - 22 Feb 2006 18:13 GMT
What i'm looking for, is a macro which finds every occurrence of
certain string, and delete the text which follows it (in the same line)

for instance, given this text:

bla bla bla //this should be removed
bla bla bla //this should be removed
bla bla bla //this should be removed

After executing the macro, I'd want to have

bla bla bla
bla bla bla
bla bla bla

I tried with the following code, expecting that it would find "//"
every time this string is in the text, but it actually doesn't do the
job

  With ActiveDocument.Content.Find
       .ClearFormatting
       .Style = wdStyleHeading3
       .Text = "//"
        Do While .Execute(Forward:=True, Format:=True) = True
             MsgBox "se encontró //"
        Loop
 End With

I'm really new in VBA, so any tips would be apreciated

tnx - jm
Greg - 22 Feb 2006 18:40 GMT
If you line ends with a paragraph mark, you could use:

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
 .ClearFormatting
 .Text = "//"
 While .Execute
   oRng.MoveEndUntil vbCr
   oRng.Delete
 Wend
End With
End Sub
julian_m - 22 Feb 2006 18:48 GMT
> If you line ends with a paragraph mark, you could use:
>
[quoted text clipped - 10 lines]
> End With
> End Sub

It works like a charm ;) Tnx

regards - jm
 
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.