MS Word Macro - Delete Paragraphs

后端 未结 1 1260
予麋鹿
予麋鹿 2021-01-15 12:23

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 conta

相关标签:
1条回答
  • 2021-01-15 13:18

    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!

    0 讨论(0)
提交回复
热议问题