2 Quick Ways to Count the Number of Highlighted Words in Your Word Document

In this article, we would like to offer you 2 quick ways to count the number of highlighted words in your Word document.

Count the Number of Highlighted Words in Your Word Document

From time to time, we would highlight texts in different topics with different colors. In case you want to count the total number of highlighted words, you must understand that there is no direct way in Word to do this task. But as workarounds, you can choose to pick either one of the following methods in different cases.

Method 1: Count All Highlighted Words in Different Colors

  1. First of all, press “Alt+ F11” to open the VBA editor in Word.
  2. Next click “Normal” on the left column.
  3. Then click “Insert” on the menu bar.
  4. On the drop-down menu, choose “Module”.

Insert a New Module

  1. And double click on the new module to open it.
  2. Paste the following macro there:
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
              Loop
         End With
    End With
 
    MsgBox ("The total number of highlighted words is " & nHighlightedWords & " .")
 
    Application.ScreenUpdating = True
    Set objDoc = Nothing
End Sub
  1. Last but not the least, click “Run” button or hit “F5” to execute the codes.Click “Run” Button

There will be a message box showing up, such as below:

Result of Counting All Highlighted Words in Different Colors

Method 2: Count All Highlighted Words in a Specific Color

As we mentioned above, there can be several highlight colors applied to your Word document. Therefore, it’s kind of difficult to get the word count of highlighted words in a particular color. Fortunately, we could always rely on macro to do some customized task.

  1. First of all, repeat steps in method 1 to install and run a macro.
  2. Then replace with this macro:
Sub CountWordsInASpecificHighlightColor()
    Dim objDoc As Document
    Dim objWord As Object
    Dim nHighlightedWords As Long
    Dim strHighlightColor As String
 
    Application.ScreenUpdating = False
    Set objDoc = ActiveDocument
    nHighlightedWords = 0
    strHighlightColor = InputBox("Choose a Highlight colour (enter the value):" & vbNewLine & _
      vbTab & "Auto" & vbTab & vbTab & "0" & vbNewLine & _
      vbTab & "Black" & vbTab & vbTab & "1" & vbNewLine & _
      vbTab & "Blue" & vbTab & vbTab & "2" & vbNewLine & _
      vbTab & "BrightGreen" & vbTab & "4" & vbNewLine & _
      vbTab & "DarkBlue" & vbTab & vbTab & "9" & vbNewLine & _
      vbTab & "DarkRed" & vbTab & vbTab & "13" & vbNewLine & _
      vbTab & "DarkYellow" & vbTab & "14" & vbNewLine & _
      vbTab & "Gray25" & vbTab & vbTab & "16" & vbNewLine & _
      vbTab & "Gray50" & vbTab & vbTab & "15" & vbNewLine & _
      vbTab & "Green" & vbTab & vbTab & "11" & vbNewLine & _
      vbTab & "Pink" & vbTab & vbTab & "5" & vbNewLine & _
      vbTab & "Red" & vbTab & vbTab & "6" & vbNewLine & _
      vbTab & "Teal" & vbTab & vbTab & "10" & vbNewLine & _
      vbTab & "Turquoise" & vbTab & "3" & vbNewLine & _
      vbTab & "Violet" & vbTab & vbTab & "12" & vbNewLine & _
      vbTab & "White" & vbTab & vbTab & "8" & vbNewLine & _
      vbTab & "Yellow" & vbTab & vbTab & "7", "Pick Highlight Color")
 
    For Each objWord In objDoc.Words
        If objWord.HighlightColorIndex = strHighlightColor Then
           nHighlightedWords = nHighlightedWords + 1
        End If
    Next objWord
 
    MsgBox ("The number of highlighted words is " & nHighlightedWords & " .")
 
    Application.ScreenUpdating = True
    Set objDoc = Nothing
End Sub
  1. Next in “Pick Highlight Color” box, enter a color value and click “OK”. For example, here we enter “7”, representing the yellow color.Enter a Color Value & Click OK
  2. Now here is the outcome:Count Highlighted Words in Yellow

Smartly Solve the Document Corruption Issue

Now and then, you can encounter with Word damage. The worst of it is that it can lead to broken documents. While you can utilize the built-in feature in Word to recover your document, you can also resort to another clever choice that is to get a repairing tool to retrieve your data in the least time.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted xls and pdf repair software products. For more information visit www.datanumen.com

Comments are closed.