用于删除 Word 文档中所有重复文本实例的宏

发布于 2024-10-14 19:57:17 字数 186 浏览 2 评论 0原文

我正在寻找一种简单的方法来删除 Word 2007 文档中的重复文本。如果查找/替换命令有一些快捷方式,我没有看到它。否则,有人可以建议我如何编写一个如下所示的宏:

1-选择一个文本块(可以是多个段落,有项目符号点等)。
2- 运行宏或执行命令。
3- 宏或命令删除所选文本块的所有实例。

这里有什么见解吗?

I'm looking for a simple way to delete repeated text in a Word 2007 document. If there are some shortcuts with the Find/Replace commands, I'm not seeing it. Otherwise, can someone recommend how I might write a macro that works like the following:

1- Select a block of text (could be mulitple paragraphs, have bullet points, etc).
2- Run the macro or do the command.
3- The macro or command deletes all instances of the selected text block.

Any insight here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月棠 2024-10-21 19:57:17

Selection.Text 返回当前选择的文本。

原则上,替换命令的语法是:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = Selection.Text
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

替换为空字符串,从而删除要查找的文本的每个实例。

但是:您当然必须决定如何处理选定文本的格式,也许必须首先分析您选定的块,因为替换可能不适用于 Selection.Text 忽略的控制字符...这这只是开始,您需要指定您想要什么,然后再次询问您自己或我们。同时录制宏和vba参考这个词是你的朋友。

Selection.Text returns the current selection's text.

In principle, the syntax for your Replace command is:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = Selection.Text
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

You replace by an empty string, thus delete every instance of the text to find.

But: You have to decide of course how to handle the formatting of the selected text, maybe have to analyze your selected block first because replacing might not work with control chars neglected by Selection.Text ... This is just the start, you need to specify what you want and then ask again, yourself or us. Meanwhile Record macro and the word vba reference are your friends.

寒冷纷飞旳雪 2024-10-21 19:57:17

对于字母数字文本(没有换行符),您可以使用查找/替换,但是一旦您进入项目符号、新段落等领域,它将不再进行精确匹配。如果您经常需要这样做,我建议使用像 LaTeX 这样的程序来编写文档。 LaTeX 允许您对大文本块进行这种精确匹配。如果您使用的是 Windows 计算机,proTeXt 就是一个很棒的 LaTeX 软件包,可以在 http://www 找到.tug.org/protext/

For alpha number text (with out newlines), you can use Find/Replace however as soon as you get in the realm of bullets, new paragraphs, etc. it will no longer do exact matching. If you often need to do that, I would suggest using a program like LaTeX to write your documents. LaTeX would allow you do this style of exact matching of large blocks of text. If you're on a Windows machine, a great LaTeX package would be proTeXt which can be found at http://www.tug.org/protext/

岁月流歌 2024-10-21 19:57:17

我遇到了完全相同的问题,巨大的邮件列表,我只需要电子邮件。我通过复制Excel中的文本,逐句(或项目符号)过滤我想要删除的段落并删除所有行来解决这个问题。我的有270多页,效果很好(只要文本不是太长,它比逐句替换单词要快得多。)或者如果是一个选项,只需使用文本过滤器进行过滤 - 开始使用 "to:" ,那么您将在 10 秒内完成。希望有帮助。

I had exactly the same problem, huge mailing list and I just needed the emails. I solved it by copying the text in excel, filtering sentence by sentence (or bullets) the paragraph i wanted to remove and deleting all rows. Mine was more than 270 pages, worked just fine (as long as the text is not too long, it was a lot faster than replaceing sentence by sentence in word.) Or if it is an option, just filter with a text filter - begins with "to:" , then you are done in 10 secs. Hope it helps.

不醒的梦 2024-10-21 19:57:17

只需按 Ctrl+H 选择并替换文本,输入要删除的文本,然后按全部替换,将替换字段保留为空白

Just Press Ctrl+H to select and replace text, Type the text you want to remove and Press Replace All leaving replace with field BLANK

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文