PDA

View Full Version : Find and delete text between strings



Horace
09-24-2008, 06:21 PM
I want to remove parts of a document. The text is like:

Good good good
good good good
STARTFLAG
bad bad bad
bad bad bad
ENDFLAG
good good good
STARTFLAG
bad bad bad
bad bad bad
ENDFLAG
good good good
...

So I need a script that:

1. Parses through until it hits "STARTFLAG"
2. Saves that spot in a variable
3. Searches until it hits "ENDFLAG"
4. Saves that spot in a variable
5. Sets the Range including the variables to ""
6. Goto 1

Can anyone help?

Thanks a million!

TonyJollans
09-25-2008, 01:11 AM
Find & Replace:

Check "Use Wildcards" (click "More" if you don't see it)
Find: STARTFLAG*ENDFLAG
Replace: (empty)
Press Replace All

fumei
09-25-2008, 12:20 PM
Or, if you really want a script...
Sub GoodDog_BadDog()
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
.Forward = True
.Text = "STARTFLAG*ENDFLAG"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End Sub