Steps to do:
- Loop through the collection of paragraphs
- Check if paragraph contains searched string
- if contains, skip to next paragraph
- if not, delete
Sample code:
Option Explicit
Sub SearchAndDestroy()
Dim p As Paragraph
Dim searchedText As String
On Error GoTo Err_SearchAndDestroy
searchedText = "Delete me"
For Each p In ThisDocument.Paragraphs
If InStr(1, p.Range.Text, searchedText, vbBinaryCompare) > 0 Then GoTo SkipNext
p.Range.Delete Unit:=wdParagraph, Count:=1
SkipNext:
Next
Exit_SearchAndDestroy:
Exit Sub
Err_SearchAndDestroy:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_SearchAndDestroy
End Sub