Deleting variable ranges based on keyword
So basically what I'm looking to do is sort a long document of text entries in the following format:
Name:XXXXXXXXXXXXX...
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX
XXXXXKeywordXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXLocation:
each separated by one or more spaces.
What I want to do is delete between "Name" and "Location: " if the keyword is found in the body of text. There may be zero, one or many instances of the keyword throughout the document.
What I have so far is listed below. It works, but only if the keyword is within the very first body of text and it will keep deleting any contiguous keyword containing paragraphs after that. But, it does nothing if the keyword is not in the first body of text.
----------------------------------
Set range1 = ActiveDocument.Content
Set range2 = ActiveDocument.Content
Set range3 = ActiveDocument.Content
range1.Find.Execute FindText:="Name", _
Forward:=True
range2.Find.Execute FindText:="Location: ", _
Forward:=True
If range1.Find.Found = True And range2.Find.Found = True Then
range3.SetRange (range1.End - 4), (range2.End + 1)
End If
range3.Find.Execute FindText:="Orthopaedic", _
Forward:=True
If range3.Find.Found = True Then
range3.SetRange (range1.End - 4), (range2.End + 1)
range3.Delete
End If
----------------------------------------------------
I would greatly appreciate any help y'all would see fit to offer.
Thanks!
Q
|