deleting text after certain string

J

julian_m

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
 
G

Greg

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
 
J

julian_m

Greg said:
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

It works like a charm ;) Tnx

regards - jm
 

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