View Single Post
 
Old 09-09-2020, 12:20 AM
djced djced is offline Windows XP Office 2007
Novice
 
Join Date: Jan 2020
Posts: 5
djced is on a distinguished road
Question Delete text between 'from' 'to' text strings

In various stereotyped documents, I am trying

1. to delete few lines and paragraphs in between text strings "service on the seller" to "service on the Buyer"
I tried this code, but it deletes all the lines after "service on the seller" till end of the document, even after removing or changing "myrange.End"

Code:
Sub SelectRangeStarttext()
    Selection.HomeKey Unit:=wdStory
    
    Dim myrange As Range
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Execute FindText:="service on the seller", Forward:=True, Wrap:=wdFindStop 'this will initiate the start word '"The value for the purpose of court fee and jurisdiction"
        Set myrange = Selection.Range
        myrange.End = ActiveDocument.Range.End
        myrange.Start = myrange.Start
        myrange.End = myrange.End + InStr(myrange, "service on the Buyer") ' this will initiate the end word
        myrange.Select
        
        Selection.Delete
    End With
End Sub
2. also i need to delete page containing text strings "removal Slip"

thanking you for your support
Reply With Quote