MS Word Macro - Delete Paragraphs
Can someone please help me with a MS Word macro that will search for a specific character in every paragraph of the whole document and delete paragraphs that do NOT contain that character.
I don't know anything about VBA, but I ended up with a huge and cumbersome document that I need to quickly edit.
+2
Surge Naegan
a source
to share
2 answers
Here's a quick macro that should do what you want - use with care and don't forget to back up!
Set the value to "search" as the text you are looking for. This is very crude and will delete the paragraph unless your text appears somewhere inside it.
Sub DeleteParagraphContainingString()
Dim search As String
search = "delete me"
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
Dim txt As String
txt = para.Range.Text
If Not InStr(LCase(txt), search) Then
para.Range.Delete
End If
Next
End Sub
I tried this in Office 2007. A bit scary, but it seems to work!
+3
a source to share