PDA

View Full Version : [SOLVED:] Help with Macro to Remove MS Word Comments



tstan
02-29-2016, 07:53 AM
Hello,

Can anyone help me create a macro that removes certain Comments from a document, while leaving others in place? I need to remove Comments that contain the letters, "HL" followed by a number (e.g., HL1). I've tried the Macro Recording feature, but it doesn't work because the number of Comments varies among documents and I only want to remove some of the Comments.

Please let me know if there is a possible solution.

Thanks!

tstan
02-29-2016, 09:38 AM
Thank you for your time, I found the answer.

Sub RemoveHLComment()
Dim oCom As Comment

If ActiveDocument.Comments.Count = 0 Then
MsgBox "No comments found."
Exit Sub
End If

For Each oCom In ActiveDocument.Comments
'Delete all comments that include the text specified in "XXX"
If InStr(1, oCom.Range.Text, "HL") > 0 Then
oCom.Delete
End If
Next oCom


End Sub