How to Get the Word Count of Highlighted Text in MS Word

Microsoft Word provides an excellent feature of Word Count in the Review tab of the Ribbon interface. Click Word Count option on the Review tab and you will get the count of Pages, Words, Characters, Paragraphs, and Lines. You can also Check/Uncheck to Include textboxes, footnotes, and endnotes.

However, when you are working on a long report, your work may also be reviewed by the peers. Reviewers may request some additions in your document. If you include the additions without highlighting them, the reviewer may have to read the whole document again. So, most probably, you will yellow-highlight the revised/updated text. You can further impress the reviewer by mentioning the number of words that you added in the updated file. This is an area where the Word Count option may not work for you. You only need to count the number of words of the highlighted text, which is not available in the standard option. Below I have mentioned two ways in which you can count the number of words of the yellow-highlighted text.

Option 1 – Using Find and Replace Option

  • Open a blank MS Word file, and write some sample text.
  • Yellow-highlight a portion of the written text in different paragraphs
  • Press Ctrl + F, and in the Navigation pane, click the down arrow after the Search icon
  • Select Advanced Find…
  • Click More >> in Find and Replace box
  • Put your cursor in Find what: box
  • Click Format button at the bottom and select Highlight
  • Again click Format button and select Highlight
  • Format below Find what box will now show ‘Not Highlight’
  • Click Replace box
  • Put a blank space in the Replace with box
  • Click Replace All
  • All your written text in the document will disappear except the highlighted text
  • You can now click the Word Count option on the Review tab to know the word count of the yellow-highlighted text
  • This option removes all the text except the yellow-highlighted text. Therefore, you should first make a copy of your document and apply the above steps on the copy of your document.

Option 2 – Using VBA Code

If you have a little experience in programming with Visual Basic for Applications (VBA), you can easily accomplish the same objective using code as follows:

  • Open your MS Word document
  • Press Alt + F11 to open VBA Code editor
  • Double-click ThisDocument in Microsoft Word Objects
  • Copy the following code under (General) (Declarations)
Sub CountAllWordsInHighlight()
    Dim objWord As Range
    Dim nHighlightedWords As Long
    Dim objDoc As Document
    Application.ScreenUpdating = False
    Set objDoc = ActiveDocument
    With Selection
         .HomeKey Unit:=wdStory
         With Selection.Find
              .Highlight = True
              Do While .Execute
                       nHighlightedWords = nHighlightedWords + Selection.Range.ComputeStatistics(wdStatisticWords)
                       Selection.Collapse wdCollapseEnd
         End With
    End With
    MsgBox ("The total number of highlighted words is " & nHighlightedWords & " .")
    Application.ScreenUpdating = True
    Set objDoc = Nothing
End Sub

Leave a Reply

Your email address will not be published.