简体   繁体   English

删除不包含Word中国家名称的段落

[英]Delete Paragraphs Not Containing Country Name in Word

I would like to delete paragraphs in Word document not containing the name of the country I am interested in. Based on the answer to another question on this site, I came up with: 我想删除Word文档中不包含我感兴趣的国家/地区名称的段落。基于对该站点上另一个问题的回答,我想到了:

Sub DeleteParagraphContainingString()

    Dim search As String
    search = "Afghan"

    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

However, this deletes EVERY paragraph in the document. 但是,这将删除文档中的每个段落。 Can anyone tell me how to fix it? 谁能告诉我如何解决?

Thanks! 谢谢! I do not know much about Word macros, as may be obvious from this question. 我对Word宏了解不多,从这个问题可以明显看出。

The problem is that the value you are searching for, "Afghan," has a capital 'A' in it, but you have changed the paragraph text to all lowercase. 问题是您要搜索的值“阿富汗”中有一个大写的“ A”,但是您已将段落文本更改为全部小写。 Change the value you are searching for to "afghan" with a lowercase 'a' and it should work. 将您要搜索的值更改为带有小写字母“ a”的“阿富汗”,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM