删除"回复此评论" line:Word

时间:2017-03-26 21:03:05

标签: ms-word word-vba

我试图写一个宏来自动删除所有"回复此评论" Word文档中的行。 我无法弄清楚如何查找 - 替换整行(包括段落标记)。 段落标记的ASCII代码是^ 013。 源文本通常从博客文章复制到Word,类似于下面。

1 个答案:

答案 0 :(得分: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