View Single Post
 
Old 07-12-2017, 07:44 PM
puff puff is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Default Problem with my script to keep all the paragraphs starting by a certain word

My goal is to save all the paragraphs starting with the word "transcript" and after that, delete all those "transcript" at the beginning of all the remaining paragraphs since they all have it.

Here's my code so far:
Code:
Sub Para()
    Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
        If InStr(1, oPara.Range.Words(1).Text, "transcript") = False Then
            oPara.Range.Delete
            oPara.Range.Delete
        ElseIf InStr(1, oPara.Range.Words(1).Text, "transcript") = True Then
            oPara.Range.Words(1).Text = Replace(oPara.Range.Words(1).Text, "Keep ", "")
        End If
    Next
End Sub
The problem is that this code will delete all of the paragraphs. Could someone help me out on this issue? Thank you very much!
Reply With Quote