2
votes

Could somebody please help me with a MS Word Macro that would search for a specific symbol in every paragraph throughout the document and delete paragraphs that DO NOT contain that symbol.

I know practically nothing about VBA, but just received a huge & unwieldy document I need to edit real fast.

1

1 Answers

6
votes

Here's a quick macro that should do what you want - use with caution, and don't forget to backup!

Set the value of 'search' to be the text that you're looking for. It's very crude, and will delete the paragraph if your text does not appear somewhere within 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've tried this on Office 2007. Bit scary, but seems to work!