none
Delete comments from 1 specific author with macro RRS feed

  • Question

  • I would like to write a macro that when called deletes the comments of a specific author.

    I tried to find them with GoTo comment andadded the name of the author, but apparently I can't delete them that way because the comment itself isn't selected.

    How could I change the code below so that it only deletes the comments from het specific author?

    Sub DeleteComments()
        Dim cm As Comment
        For Each cm In ActiveDocument.Comments
            cm.Delete
        Next
    End Sub

     

    • Edited by Piri10 Friday, August 22, 2014 6:45 AM
    Friday, August 22, 2014 6:36 AM

Answers

  • Get the correct spelling of the author name with

    Sub GetCommentAuthor()
    Dim cm As Comment
        For Each cm In ActiveDocument.Comments
            If MsgBox(cm.Author, vbOKCancel) = vbCancel Then Exit Sub
        Next
    End Sub

    then substitute where shown in bold

    Sub DeleteComments()
    Dim cm As Comment
        For Each cm In ActiveDocument.Comments
            If cm.Author = "Author Name" Then
                cm.Delete
            End If
        Next
    End Sub

    or combine the two

    Sub GetDeleteComments()
    Dim cm As Comment
    Dim strTest As String
        For Each cm In ActiveDocument.Comments
            strTest = MsgBox("Delete comment" & vbCr & cm.Range.Text & vbCr & "by " & cm.Author, vbYesNoCancel)
            Select Case strTest
                Case vbCancel: Exit Sub
                Case vbYes: cm.Delete
                Case Else
            End Select
        Next cm
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com


    • Edited by Graham MayorMVP Friday, August 22, 2014 7:54 AM
    • Marked as answer by Piri10 Friday, August 22, 2014 8:13 AM
    Friday, August 22, 2014 7:48 AM