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

查看:342
本文介绍了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天全站免登陆