Counting Words in Comments

Written by Allen Wyatt (last updated April 23, 2024)
This tip applies to Word 2007, 2010, 2013, and 2016


1

Linda wonders if there is a way to count the number of words that are within the comments (and only the comments) in a document.

The easiest way to accomplish this task is to use a macro. This is because Word makes available to VBA a Comments collection which includes all of the comments in the document. All you need to do is to step through each comment and then look at the Count property for the Words collection for the comment, in this manner:

Sub CommentWordCount1()
    Dim c As Comment
    Dim lWords As Long
    Dim sMsg As String

    For Each c In ActiveDocument.Comments
        lWords = lWords + c.Range.Words.Count
    Next c

    sMsg = "There are " & ActiveDocument.Comments.Count
    sMsg = sMsg & " comments in the document. & vbCrLf & vbCrLf
    sMsg = sMsg & "Word count: " & lWords
    MsgBox sMsg
End Sub

If you prefer, you could also use the ComputeStatistics method to come up with the word counts, like this:

Sub CommentWordCount2()
    Dim c As Comment
    Dim lWords As Long
    Dim sMsg As String

    For Each c In ActiveDocument.Comments
        lWords = lWords + c.Range.ComputeStatistics(wdStatisticWords)
    Next c

    sMsg = "There are " & ActiveDocument.Comments.Count
    sMsg = sMsg & " comments in the document. & vbCrLf & vbCrLf
    sMsg = sMsg & "Word count: " & lWords
    MsgBox sMsg
End Sub

When you compare the results from the two macros, you may notice a difference in word counts. This is because of the way that the CompuStatistics method treats punctuation when doing its calculations. You'll want to compare the results and, based on the characteristics of the information in your comments, choose the approach that best suits your needs.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13531) applies to Microsoft Word 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Different Ways of Inserting Dates

Word provides a couple of different ways you can insert the current date into a document. Which method should you choose? ...

Discover More

Beginning a Mail Merge

Performing a mail merge can be intimidating to some people. It needn't be; Word provides a handy step-by-step wizard that ...

Discover More

Getting Identical Margins

Need to get the margins on your document exactly right? It can be a challenge to get the Word settings where you need ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Changing the User Name in Existing Comments

Want to change the name that Word associates with various comments previously added to your document? Here are some ideas ...

Discover More

Jumping To a Comment

Got a document with lots of comments in it? You can navigate from comment to comment with ease by using the Go To tab of ...

Discover More

Struggling with New Changes to Track Changes

In the latest versions of Microsoft 365, the company has introduced an entirely new way to deal with markup comments. ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2020-06-23 10:34:35

Bartosz

well done! the question is whether it is possible to count all the characters in the entire document and in the comments in one script?


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.