PDA

View Full Version : [SOLVED:] Counting the number of comments by authors



h2whoa
06-12-2018, 07:19 AM
Hi all,

I'm wondering if there is a way to count the number of comments by specific authors. I'm modifying a comment grid generator and have added an option to exclude comments by up to 3 specific authors in the grid.

At the end, a little message box opens up that says "x comments found in the document".

I would like to make x only count the authors who weren't excluded by the user.

My thinking is that the easiest way is to subtract the number of comments by the excluded authors from the overall comment count:


x = ActiveDocument.Comments.Count - (number of comments from author 1 + number of comments from author 2 + number of comments from author 3)

I'm sure that there is an easy way to do this, but I'm too stupid to work it out!

Thank you.

h2whoa
06-15-2018, 04:30 AM
Me again...

I'm hoping to be able to create a list of people who have commented on, or made tracked changes to, a document. It's part of something else I'm trying to tweak, but I should be able to work out what I need to do if anyone knows if there is a way have a message box open up and say:

'The following people have made comments or revisions on this document:
AuthorA
AuthorB
AuthorC...'

Any help appreciated.

macropod
06-15-2018, 04:27 PM
Try:

Sub DemoA()
Dim StrCmnt As String, ArrAuth, i As Long, j As Long, k As Long
StrCmnt = vbCr: ArrAuth = Array("Author1", "Author2", "Author3")
With ActiveDocument
For i = LBound(ArrAuth) To UBound(ArrAuth)
k = 0
For j = 1 To .Comments.Count
With .Comments(j)
If .Author = ArrAuth(i) Then k = k + 1
End With
Next
StrCmnt = StrCmnt & vbCr & ArrAuth(i) & " - " & k
Next
End With
MsgBox "Comment Count by Designated Author:" & StrCmnt
End Sub
and:

Sub DemoB()
Dim StrCmnt As String, StrRevn As String, i As Long
StrCmnt = vbCr: StrRevn = vbCr
With ActiveDocument
For i = 1 To .Comments.Count
With .Comments(i)
If .Author <> "" Then
If InStr(StrCmnt, vbCr & .Author & vbCr) = 0 Then
StrCmnt = StrCmnt & .Author & vbCr
End If
End If
End With
Next
For i = 1 To .Revisions.Count
With .Revisions(i)
If .Author <> "" Then
If InStr(StrRevn, vbCr & .Author & vbCr) = 0 Then
StrRevn = StrRevn & .Author & vbCr
End If
End If
End With
Next
End With
MsgBox "Comment Authors:" & StrCmnt
MsgBox "Revision Authors:" & StrRevn
End Sub

h2whoa
06-18-2018, 01:26 AM
Paul, you are an absolute legend. Thank you so much!