本文介绍了使用word宏删除基于子字符串的特定段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我需要一个MS Word宏来搜索整个文档中每个段落中的特定子字符串,并删除不包含该字符串的段落。 I试过这个宏代码: Sub DeleteParagraphContainingString() Dim search As String search = 删除我 Dim para As 段落 对于 每个 para 在 ActiveDocument.Paragraphs Dim txt As String txt = pa ra.Range.Text 如果 不 InStr(LCase(txt),搜索)然后 para.Range.Delete 结束 如果 下一步 结束 Sub 但它虽然它有该子字符串,但删除所有段落。我没有任何线索在代码中哪里出错。解决方案 I need a MS Word Macro that would search for a specific substring in every paragraph throughout the document and delete paragraphs that don't contain that string.I tried this macro code: 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 SubBut it deletes all the paragraph though it has that subtring. I don't have any clue where is the wrong in the code. 解决方案 这篇关于使用word宏删除基于子字符串的特定段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-31 07:38