How can one go about deleting text between a start word and an end word.
I have a huge text extract of about 1 million plus words and I want create a VBA Script which will delete all the unwanted text.
Fortunately I have the key words to look for and delete all the text after those key words up to a specific end point which I would like to enter.
I need a program that can find these key words and dedicate them as the start words and then an end word as the end position and to delete all the text in between them. If the word is situated within a paragraph, I would like to delete the paragraph.
Program below does all of what I am looking for, except it is not able to loop through the document and do it to other messages with the same start and end position.
Sub SelectRangeBetween()
Selection.HomeKey Unit:=wdStory
'Selection.TypeText Text:="hello"
' The Real script
Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute findtext:="From: [email protected]", Forward:=True, Wrap:=wdFindStop 'this will initiate the start word
Set myrange = Selection.Range
myrange.End = ActiveDocument.Range.End
myrange.Start = myrange.Start
myrange.End = myrange.End + InStr(myrange, "This message has been scanned ") ' this will initiate the end word
myrange.Select
'Selection.Delete
End With
End Sub
Find
Statements and then use a Loop to go through the entire document – Jean-Pierre Oosthuizen