Find and delete

S

Steve Barber

Hi,

I am looking fo some VBA that will search for a certain string e.g.
"*Begin*" and then delete all the text between that string and another e.g.
"*End*".

so for the following text

This is what I want
*Begin*
This is what I dont want
*End*
and now it is clean



I would end up with

This is what I want
and now it is clean

Any help with this would be very much appreciated

Thank you all in advance

Steve Barber
 
M

mbaird

You would use the wildcard match Begin*End

With Selection.Find
.ClearFormatting
.Text = "Begin*End"
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With


Mark Baird
 

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