Reputation: 108
I'm attempting to write a macro to automatically delete all "Reply to this comment" lines in a Word doc.
I can't figure out how to Find-Replace the entire line (including the paragraph mark).
The ASCII code for the paragraph mark is ^013.
The source text is typically copied from a blog post into Word similar to below.
Upvotes: 0
Views: 304
Reputation: 108
The solution is below. It counts occurrences, then loops through the text deleting the phrase and paragraph mark as it goes:
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
Upvotes: 1