MS Word 宏 - 删除段落 [英] MS Word Macro - Delete Paragraphs

查看:31
本文介绍了MS Word 宏 - 删除段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我使用 MS Word 宏,它可以在整个文档的每个段落中搜索特定符号并删除不包含该符号的段落.

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.

我对 VBA 几乎一无所知,但刚刚收到了一个巨大的 &笨重的文档,我需要快速编辑.

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

推荐答案

这里有一个快速宏,它可以满足您的需求 - 谨慎使用,不要忘记备份!

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

我在 Office 2007 上试过这个.有点吓人,但似乎有效!

I've tried this on Office 2007. Bit scary, but seems to work!

这篇关于MS Word 宏 - 删除段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆