【问题标题】:Delete "Reply to this comment" line: Word删除“回复此评论”行:Word
【发布时间】:2020-07-05 07:16:15
【问题描述】:

我正在尝试编写一个宏来自动删除 Word 文档中的所有“回复此评论”行。

我不知道如何查找-替换整行(包括段落标记)。

段落标记的 ASCII 码是 ^013。

源文本通常从博客文章复制到类似于下面的 Word 中。

【问题讨论】:

  • 你能展示或分享一个word doc的图片吗?
  • "Reply to this comment^p" 列在特殊字符extendoffice.com/documents/word/…
  • @Slai - 这是我尝试的第一件事,但没有成功。弹出错误对话框,提示“Word 已完成对文档的搜索,未找到搜索项”。使用 ^p 可以单独使用,但不能与其他文本一起使用。
  • @SeanS 听起来^p 之前可能有一些不可打印的字符。你可以试试通配符comment*^pcybertext.wordpress.com/2012/02/13/…
  • @Slai - 我也无法让允许通配符工作,但我想出了一个解决方法,替换“回复此评论”,然后删除一个字符,即 ^p。上面列出了 VBA 代码。

标签: vba ms-word


【解决方案1】:

解决方案如下。它计算出现次数,然后遍历删除短语和段落标记的文本:

Sub DeleteReplyComments()
  ' loop through lines to count Replies
    Selection.Find.ClearFormatting
    MyDoc = ActiveDocument.Range.Text
    txt = "Reply to this comment"
    t = Replace(MyDoc, txt, "")
    nCount = (Len(MyDoc) - Len(t)) / Len(txt)
  ' delete Replies and ^p's
    For i = 1 To nCount
        With Selection.Find
            .Text = "Reply to this comment"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveEnd Unit:=wdParagraph
        Selection.Delete Unit:=wdCharacter, Count:=1
    Next i
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2011-12-18
    相关资源
    最近更新 更多