Highlight words from a word list

Please Note:
This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Highlight Words from a Word List.

Written by Allen Wyatt (last updated May 23, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Paul has a document that he needs to check against a word list contained in another document. If the document being checked contains one of the words in the list, then the word in the document (not in the word list) needs to be highlighted by being made bold. The word list is large, on the order of 20,000 words, and Paul is wondering what the best way to do this is.

There are two ways you can proceed. The first is to write your own macro that will do the comparisons for you. If you put the words you want checked into a document named “checklist.doc” in the C: drive, then the following macro can be used:

Sub CompareWordList()
    Dim sCheckDoc As String
    Dim docRef As Document
    Dim docCurrent As Document
    Dim wrdRef As Object

    sCheckDoc = "c:checklist.doc"
    Set docCurrent = Selection.Document
    Set docRef = Documents.Open(sCheckDoc)
    docCurrent.Activate

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Font.Bold = True
        .Replacement.Text = "^&"
        .Forward = True
        .Format = True
        .MatchWholeWord = True
        .MatchCase = True
        .MatchWildcards = False
    End With

    For Each wrdRef In docRef.Words
        If Asc(Left(wrdRef, 1)) > 32 Then
            With Selection.Find
                .Wrap = wdFindContinue
                .Text = wrdRef
                .Execute Replace:=wdReplaceAll
            End With
        End If
    Next wrdRef

    docRef.Close
    docCurrent.Activate
End Sub

All you need to do is have the document open that you want checked, and then run the macro. If the document containing the words to check is named differently or in a different location, just change the line that sets sCheckDoc so that it has a different full path name for the document.

Basically, the macro grabs each word from the word list and then does a Find and Replace operation using that word in the document. If you have many, many words in the word list, then the macro can take quite a while to run—20,000 Find and Replace operations is quite a few!

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 (1173) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Highlight Words from a Word List.

Author Bio

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. Learn more about Allen…

MORE FROM ALLEN

Reusing a Bookmark

Bookmarks in Word are just like bookmarks used in paper books, any given bookmark may be reused to mark a new location. …

Discover More

Moving Custom Formats to Number Formatting Categories

Moving your custom formats into a formatting category other than «custom» isn’t something you can do in Excel. Here’s …

Discover More

Error in Linked PivotTable Value

Excel allows you to link to values in other workbooks, even if those values are in PivotTables. However, Excel may …

Discover More

I have a typing field that’s linked to the afinn word list. This is the project i am using: https://github.com/CodingTrain/website/tree/master/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5

The detected words from the list are written below, telling the score of the word.

I want the detected words to be highlighted directly in the typing field. (shades of red for negativ words with a score from -5 to -1 and shades of green for positive words with a score from +1 to +5)

I was not able to create an example that runs in stackoverflow, but here’s an example from github how it works right now:
https://darenr.github.io/afinn/

The piece of code will be used on a website.
The code is using the p5.js library and the afinn wordlist (json file): https://github.com/CodingTrain/website/blob/master/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/afinn111.json
I normally do design, so i’m really not good in coding. I hope you understand the question.

javascript:

// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Code for: https://youtu.be/VV1JmMYceJw


var afinn;

function preload() {
  afinn = loadJSON('afinn111.json');
}


function setup() {
  noCanvas();
  console.log(afinn);

  var txt = select('#txt');
  txt.input(typing);

  function typing() {
    var textinput = txt.value();
    var words = textinput.split(/W/);
    console.log(words);
    var scoredwords = [];
    var totalScore = 0;
    for (var i = 0; i < words.length; i++) {
      var word = words[i].toLowerCase();
      if (afinn.hasOwnProperty(word)) {
        var score = afinn[word];
        console.log(word, score);
        totalScore += Number(score);
        scoredwords.push(word + ': ' + score + ' ');
      }
    }
    var scorePar = select('#scoreP');
    scorePar.html('score: ' + totalScore);
    var comp = select('#comparativeP');
    comp.html('comparative: ' + totalScore / words.length);
    var wordlist = select('#wordlistP');
    wordlist.html(scoredwords);

    //console.log(txt.value());
  }
}





function draw() {

}

html:

<html>
<head>
  <meta charset="UTF-8">
  <title>AFINN-111 demo</title>
  <script language="javascript" type="text/javascript"             src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/p5.min.js"></script>
  <script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/addons/p5.dom.min.js"></script>
  <script language="javascript" type="text/javascript" src="sketch.js">    </script>
</head>
<body>
  <h1>AFINN Sentiment Demo</h1>

  <p>
    Type here:<br />
    <textarea id="txt" cols=50 rows=10></textarea>
  </p>

  <p id="scoreP"></p>
  <p id="comparativeP"></p>
  <p id="wordlistP"></p>

</body>
</html>

Problem:
I need the scored words from the afinn list to be highlighted directly in the typing field. In shades of red (negative words, from -5 to -1) and shades of green (positve words, from +1 to +5)

I hope anyone can help! It would be so much appreciated!

Strongly based on my answer at How to insert a symbol to the beginning of a line for which a word appears?. However, I had to extend the logic to handle multiple color assignments. Syntax is multiple invocations of WordsToNote{space separated list}{color} and then NoteWords{multiple paragraph input}

Macros in the input are limited to style (e.g., textit) and size (e.g., small) changes. Otherwise, only plain text is accepted.

As detailed in the referenced answer, I adapt my titlecaps package, which normally capitalizes the first letter of each word in its argument, with a user-specified list of exceptions. Here, instead of capitalizing the words, I leave them intact. However, I trap the user-specified word exceptions and use them to set a different color.

In this extension of that method, I had to revise two titlecaps macros: titlecap and seek@lcwords.

The method cannot handle word subsets, but it can ignore punctuation.

EDITED to fix bug when flagged word appears with punctuation, and issue with first word of paragraphs.

documentclass{article}
usepackage{titlecaps}
makeatletter
renewcommandtitlecap[2][P]{%
  digest@sizes%
  if Tconverttildedef~{ }fi%
  redefine@tertius%
  get@argsC{#2}%
  seek@lcwords{#1}%
  if P#1%
    redefine@primus%
    get@argsC{#2}%
    protected@edefprimus@argi{argi}%
  else%
  fi%
  setcounter{word@count}{0}%
  redefine@secundus%
  def@thestring{}%
  get@argsC{#2}%
  if P#1protected@edefargi{primus@argi}fi%
  whiledo{value{word@count} < narg}{%
    addtocounter{word@count}{1}%
    if Fcsname found@wordroman{word@count}endcsname%
      notitle@word{csname argroman{word@count}endcsname}%
      expandafterprotected@edefcsname%
           argroman{word@count}endcsname{@thestring}%
    else
      notitle@word{csname argroman{word@count}endcsname}%
      expandafterprotected@edefcsname%
         argroman{word@count}endcsname{color{%
           csname colorromannumeralvalue{word@count}endcsname}%
      @thestringcolor{black}{}}%
    fi%
  }%
  def@thestring{}%
  setcounter{word@count}{0}%
  whiledo{value{word@count} < narg}{%
    addtocounter{word@count}{1}%
    ifthenelse{value{word@count} = 1}%
   {}{add@space}%
    protected@edef@thestring{@thestring%
      csname argroman{word@count}endcsname}%
  }%
  let~SaveHardspace%
  @thestring%
  restore@sizes%
un@define}

% SEARCH TERTIUS CONVERTED ARGUMENT FOR LOWERCASE WORDS, SET FLAG
% FOR EACH WORD (T = FOUND IN LIST, F= NOT FOUND IN LIST)
renewcommandseek@lcwords[1]{%
kill@punct%
  setcounter{word@count}{0}%
  whiledo{value{word@count} < narg}{%
    addtocounter{word@count}{1}%
    protected@edefcurrent@word{%
      csname argromannumeralvalue{word@count}endcsname}%
    deffound@word{F}%
    setcounter{lcword@index}{0}%
    expandafterdefcsname%
            found@wordromannumeralvalue{word@count}endcsname{F}%
    whiledo{value{lcword@index} < value{lc@words}}{%
      addtocounter{lcword@index}{1}%
      protected@edefcurrent@lcword{%
        csname lcwordromannumeralvalue{lcword@index}endcsname}%
%% THE FOLLOWING THREE LINES ARE FROM DAVID CARLISLE
  protected@edeftmp{noexpandscantokens{defnoexpandtmp%
   {noexpandifthenelse{noexpandequal{current@word}{current@lcword}}}}}%
  tmpifhmodeunskipfitmp
%%
      {expandafterdefcsname%
            found@wordromannumeralvalue{word@count}endcsname{T}%
      expandafterprotected@edefcsname colorromannumeralvalue{word@count}endcsname{%
       csname CoLoRcsname lcwordromannumeralvalue{lcword@index}endcsnameendcsname}%
      setcounter{lcword@index}{value{lc@words}}%
      }%
      {}%
    }%
  }%
if P#1deffound@wordi{F}fi%
restore@punct%
}
makeatother
usepackage{xcolor}
newcommandWordsToNote[2]{Addlcwords{#1}edefassignedcolor{#2}%
  assigncolor#1 relaxrelax}
defassigncolor#1 #2relax{%
  expandafteredefcsname CoLoR#1endcsname{assignedcolor}%
  ifxrelax#2elseassigncolor#2relaxfi%
}
newcommandNoteWords[1]{NoteWordsHelp#1parrelax}
longdefNoteWordsHelp#1par#2relax{%
  titlecap[p]{#1}%
  ifxrelax#2elseparNoteWordsHelp#2relaxfi%
}
begin{document}
WordsToNote{foo bar at}{red}
WordsToNote{Nulla dolor nulla}{cyan}
WordsToNote{amet est et}{orange}
WordsToNote{Lorem Ut ut felis}{green}
NoteWords{
textbf{Lorem ipsum dolor foo sit amet, bar consectetuer adipiscing elit}. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus
rhoncus sem. textit{Nulla et lectus foo} vestibulum urna fringilla ultrices.
Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien
est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem
vel leo ultrices bibendum. scshape Aenean faucibus. Morbi dolor nulla,
malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper
nulla. Donec varius orci eget risus. upshape Duis nibh mi, congue eu,
accumsan eleifend, bar sagittis quis, diam. Duis eget orci sit amet orci
dignissim rutrum.

textsf{Lorem ipsum dolor sit amet}, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, foo vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus
rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien
est, iaculis in, pretium quis, viverra ac, bar nunc. Praesent eget sem
vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,
malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper
nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,
accumsan eleifend, sagittis quis, diam. Large Duis eget orci sit amet orci
dignissim rutrum.normalsize
}
end{document}

enter image description here

Old

10-16-2016, 11:57 PM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default

How to highlight text in a Word document using a word list from another document


Hello.

I have a MS Word document that I need to check against a table of terms contained in another MS Word document. Essentially, I need to highlight the phrases/words in the document that coincide with phrases/words contained in the table of terms. The table of terms is formatted like this:

duplicate line item
duplicate procedures
duplication of benefits
Durable Medical Equipment (DME)
durable medical equipment exceeds rental cost
durable medical equipment maximum frequency

As a first attempt, I tried the code below. The problem is that it highlights EVERY SINGLE WORD from the table of terms. As I explained, I only want to highlight the phrases/words that coincide exactly with the phrases/words from the table (although many of the entries are single words, as a matter of fact). I tried to modify the code but didn�t have any luck. Thanks in advance for whatever help/guidance you can give me.

Code:

Sub CompareWordList()
      Dim sCheckDoc As String
      Dim docRef As Document
      Dim docCurrent As Document
      Dim wrdRef As Object
   
      sCheckDoc = "c:checklist.doc"
      Set docCurrent = Selection.Document
      Set docRef = Documents.Open(sCheckDoc)
      docCurrent.Activate
   
      With Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Replacement.Highlight = True
          .Replacement.Text = "^&"
          .Forward = True
          .Format = True
          .MatchCase = True
          .MatchWildcards = False
      End With
   
      For Each wrdRef In docRef.Words
          If Asc(Left(wrdRef, 1)) > 32 Then
              With Selection.Find
                  .MatchWholeWord = True
                  .Wrap = wdFindContinue
                  .Text = wrdRef
                  .Execute Replace:=wdReplaceAll
              End With
          End If
      Next wrdRef
   
      docRef.Close
      docCurrent.Activate
  End Sub

Reply With Quote

Old

10-17-2016, 01:05 AM

Default


There have been numerous threads in this forum discussing the kind of thing you want, complete with solutions. Try a search.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

10-17-2016, 07:13 AM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default


Thank you, I’ll try.

Reply With Quote

Old

10-25-2016, 10:01 PM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default


Hello, Macropod.

Thank you for your advice. Through some search and trial and error I was able to do what I aimed: Highlight words and, specially, full phrases I wanted to identify in my text. I have now another problem: Next to each term that has been identified and highlighted I need to add, in hidden text, a small (glossary like) explanation of that highlighted term.

I start with a table that in the first column contains the terms that are going to be identified and highlighted. The second column contains the glossary-like explanation of the terms contained in the first column. I’m struggling to produce a feasible code. Would you have any recommendation and/or advice on how to proceed? I greatly appreciate beforehand any help you can offer me. (These are really my first attempts into VBA programming and, after some considerable search, I haven’t found any thread addressing this matter.)

Reply With Quote

Old

10-28-2016, 01:24 AM

Default


You could use Word’s ‘comment’ tool to add the explanatory text. For example:

Code:

Sub Demo()
Application.ScreenUpdating = False
Dim FRDoc As Document, strFnd As String, strRep As String, i As Long
Set FRDoc = Documents.Open("Drive:FilePathFindTableData.doc", _
  ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)
For i = 1 To FRDoc.Tables(1).Rows.Count
  strFnd = Split(FRDoc.Tables(1).Cell(i, 1).Range.Text, vbCr)(0)
  strRep = Split(FRDoc.Tables(1).Cell(i, 2).Range.Text, vbCr)(0)
  With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .MatchCase = True
      .MatchWholeWord = True
      .MatchWildcards = False
      .Wrap = wdFindStop
      .Text = strFnd
      .Execute
    End With
    Do While .Find.Found
      .HighlightColorIndex = wdBrightGreen
      .Comments.Add .Duplicate, strRep
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
Next
Application.ScreenUpdating = True
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

10-30-2016, 12:27 PM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default


Thank you very much, macropod!

You are truly a master!

I do appreciate your beautiful, elegant solution. Thank you for taking the time to address my question!

I applied your code to one of my texts and it works like a charm. However, there is a little problem I’m trying to resolve applying the same idea you suggested (using Comments for the explanatory text): My table of terms is rather large (about 4300 rows) and running the code takes a long time –more than 6 or 7 minutes for a small text (2 pages) that I’m using for testing. The code below, which I used to only highlight the matching terms, took 20 seconds or so for the same text. Would adding the comments add that much time?

Once again, macropod, thank you very much for your help!


PS. Seeing your code really gives me the motivation and inspiration to learn VBA in depth. (Any recommendation for a text or handbook I could use?)

Code:

Sub Finder()
      Dim sCheckDoc As String
      Dim docRef As Document
      Dim docCurrent As Document
      Dim wrdRef As String
      Dim wrdPara As Paragraph
   
      sCheckDoc = "c:FilePathGlossary.docx"
      Set docCurrent = Selection.Document
      Set docRef = Documents.Open(sCheckDoc)
      docCurrent.Activate
   
      With Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Replacement.Highlight = True
          .Replacement.Text = "^&"
          .Forward = True
          .Format = True
          .MatchWholeWord = False
          .MatchCase = False
          .MatchWildcards = False
      End With
   
      For Each wrdPara In docRef.Paragraphs
          wrdRef = wrdPara.Range.Text
          wrdRef = Left(wrdRef, Len(wrdRef) - 1)
              If Asc(Left(wrdRef, 1)) > 32 Then
                  With Selection.Find
                  .MatchWholeWord = True
                  .MatchCase = False
                  .MatchSoundsLike = False
                  .Wrap = wdFindContinue
                  .Text = wrdRef
                  .Execute Replace:=wdReplaceAll
      End With
              End If
      Next wrdPara
   
      docRef.Close
      docCurrent.Activate
  End Sub

Reply With Quote

Old

10-30-2016, 10:46 PM

Default


Adding comments and retrieving the contents of a second column from the table will both slow down the code’s execution. The main reason for the slower execution is that the Find/Replace can’t be done as a single operation using wdReplaceAll when adding comments; instead each found instance must be individually processed.

A possible workaround would be to add the comments to the text in the table (i.e. using only one column), which you would also highlight, then let the macro copy each cell’s content to the clipboard and use for the replacement, thus:

Code:

Sub Demo()
Application.ScreenUpdating = False
Dim FRDoc As Document, strFnd As String, RngFnd As Range, i As Long
Set FRDoc = Documents.Open("C:FilePathGlossary.docx", _
  ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Replacement.Text = "^c"
  .MatchCase = True
  .MatchWholeWord = True
  .MatchWildcards = False
  .Wrap = wdFindContinue
  For i = 1 To FRDoc.Tables(1).Rows.Count
    Set RngFnd = FRDoc.Tables(1).Cell(i, 1).Range
    With RngFnd
      .End = .End - 1
      .Copy
      strFnd = .Text
    End With
    .Text = strFnd
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub

The drawback with this approach is that the format of the replacement will be the same as whatever is in the table.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

11-01-2016, 03:05 PM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default


Thank you so much, macropod!
I’m so grateful for your help.

As always, your solution is elegant.

Just for future reference, I would like to mention a little problem I had with this part of the code:

Code:

Set RngFnd = FRDoc.Tables(1).Cell(i, 1).Range
      With RngFnd
        .End = .End - 1
        .Copy
        strFnd = .Text
      End With
      .Text = strFnd

When I run it, it didn’t find any match when clearly there were many. Then I introduced a small modification:

Code:

Set RngFind = GlossaryDoc.Tables(1).Cell(i, 1).Range
    With RngFind
        .Copy
        .End = .End - 2
      strFind = .Text
    End With
    .Text = strFind

It works fine now but there is a little final problem: The replacement text keeps the column formatting (which I don’t want). It is probably a stupid question but is there a simple command to copy into the clipboard that highlighted, commented text in regular format?

Once again, Paul (macropod), thank you so very much for all of your help.

Reply With Quote

Old

11-01-2016, 03:27 PM

Default


Changing:
.End = .End — 1
to:
.End = .End — 2
indicates you have some extraneous content between the ‘find’ expression and the end-of-cell marker. A space or paragraph break, perhaps?

As for:

Quote:

there is a little final problem: The replacement text keeps the column formatting (which I don’t want).

I did warn you:

Quote:

The drawback with this approach is that the format of the replacement will be the same as whatever is in the table.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

11-01-2016, 04:44 PM

Gilvv
Gilvv is offline

How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit

Advanced Beginner

How to highlight text in a Word document using a word list from another document

 

Join Date: Oct 2016

Posts: 30

Gilvv is on a distinguished road

Default


Thanks again for explaining and clarifying.

Reply With Quote

This is a simpler version of a previous blog post—it doesn’t require you to set up and store a separate file of the words you want to highlight.

I wanted to create a list of vague words (such as some, most, often, frequently, sometimes—words that aren’t explicit or specific enough in technical writing and editing) that a simple Microsoft Word macro could find and highlight for me. I found some macros online that each partly solved the problem, and adapted one from Macropod (Paul Edstein) to suit my purposes as it was the closest to what I wanted. Full thanks to Macropod for this one.

There are several ways you can adapt this macro—I’ve commented some of my ideas in the code. I think the words are case sensitive, so if you want one with a capital (e.g. Some), you should add it as another entry.

NOTE: Copy all the code below to the clipboard—it goes off the page, so don’t type it out as you’ll miss some of it or could make a typo—then paste it into your VBA window.

Sub VagueWords()

' Source: Paul Edstein (Macropod), 8 Aug 2015: https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-search-and-replace-multiple-wordsletters-in/af4753a0-7afd-433b-910d-a148da66f2bf
' Original macro name: MultiReplace
' Adapted by Rhonda Bracey, Cybertext Consulting, 22 Feb 2020
' You could duplicate this macro with a different name (e.g. LegalWords [for must, shall, etc.]) using a different list of words in the StrFind and StrRepl lists

Dim StrFind As String
Dim StrRepl As String
Dim i As Long

' In StrFind and StrRepl, add words between the quote marks, separate with a comma, NO spaces
' To only highlight the found words (i.e. not replace with other words), either use StrRepl = StrFind OR use the SAME words in the same order in the StrRepl list as for the StrFind list; comment/uncomment to reflect the one you're using
' To replace a word with another and highlight it, put the new word in the StrRepl list in the SAME position as the word in the StrFind list you want to replace; comment/uncomment to reflect the one you're using

StrFind = "very,just,rarely,often,frequently,majority,most,minority,some,perhaps,maybe,regularly,sometimes,occasionally,best,worst,worse,better,seldom,few,many"
StrRepl = StrFind
' StrRepl = "very,just,rarely,often,frequently,majority,most,minority,some,perhaps,maybe,regularly,sometimes,occasionally,best,worst,worse,better,seldom,few,many"
Set RngTxt = Selection.Range

' Set highlight color - options are listed here: https://docs.microsoft.com/en-us/office/vba/api/word.wdcolorindex
' main ones are wdYellow, wdTurquoise, wdBrightGreen, wdPink
Options.DefaultHighlightColorIndex = wdTurquoise

Selection.HomeKey wdStory

' Clear existing formatting and settings in Find and Replace fields
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting

With ActiveDocument.Content.Find
  .Format = True
  .MatchWholeWord = True
  .MatchAllWordForms = False
  .MatchWildcards = False
  .Wrap = wdFindContinue
  .Forward = True
  For i = 0 To UBound(Split(StrFind, ","))
    .Text = Split(StrFind, ",")(i)
    .Replacement.Highlight = True
    .Replacement.Text = Split(StrRepl, ",")(i)
    .Execute Replace:=wdReplaceAll
  Next i
End With
End Sub

For another way to do this, but instead changing the colour of a selected set of words, see https://wordribbon.tips.net/T013773_Changing_the_Color_of_a_List_of_Words.html

Update Oct 2020: A professor has made a YouTube video for his students/colleagues of this in action: https://www.youtube.com/watch?v=OIg95ETFxMQ

[Links last checked June 2020]

Illustration: Write Very Much Better w/Writer's Highlighter (words Very Much are crossed out)

Writing is a process, not a one-and-done event. When a student is writing their first draft, it is important that they simply get their ideas out, mistakes and all. After that brain dump, now comes the work of editing and revising.

This is summed up beautifully in the following quote:

«You write to communicate to the hearts and minds of others what’s burning inside you, and we edit to let the fire show through the smoke.»

Arthur Plotnik

There are many tools and techniques available to assist with the editing process. A while back I covered many such resources in my blog post «Self-Editing Tools for Student Writing in Google Docs (opens in new tab)«. Recently I came across a new add-on for Google Docs that deserves to be added on to this list.

The tool is a free add-on called «Writer’s Highlighter«. It can be used in several ways, but the main focus is to highlight words in your document that match a customized list. For example, these could include overused words or phrases, including «very», «really», «stuff», and more. The add-on can also color-code your sentences based on their lengths.

See below for more details and directions on how to use this very useful tool. Or, rather I mean «this helpful tool». 

Install Writer’s Highlighter Add-on 

Writer’s Highlighter is an add-on for Google Docs. You will need to install it one time for your account, then you will be able to use it anytime you need. Here’s how to install this tool: 

  • First, open a Google Doc as normal.
  • Next, click «Add-ons» in the top menu bar.
  • Then choose «Get add-ons» from the drop-down menu.
  • You can now use the search box in the top right corner to search for «Writer’s Highlighter».
  • Alternately you can use this direct link — Google Doc Add-on link
  • Once you find the «Writer’s Highlighter» listing, click on the «+ FREE» button to begin installing it.
  • You will get a pop-up asking you to select your account.
  • Then you will get a screen asking for permissions, where you will need to scroll down and click «Allow».

And that’s it! The add-on is now installed. 

[10 Writing Prompt Tools for Creative Inspiration]

Set Up Your Word List 

For Writer’s Highlighter to work, it needs a list of words to compare against your writing. These could include words that are commonly overused, or a custom list specific to a student. The word list needs to be created in a Google Sheet. Here’s how: 

Google Sheet sample word list screenshot

  • Create a new Google Sheet as normal by going to Google Drive, clicking the «New» button, then choosing «Google Sheets».
  • Give your Sheet an appropriate title, such as «Words to Watch Out For».
  • In the first column of the Sheet, type in the words or phrases you want to search for, one word or phrase per row.
  • Note: If you want to include wildcards, such as any word that ends with an «ly» (to search for adverbs), you can use an asterisk. For example «*ly».
  • When done, copy the web address for your Sheet from the URL box at the top of your browser. You will need to paste this web address into the add-on soon.
  • Also, if you wish to let other people use your word list, you will need to share the Sheet with them as normal, so they will have access to it.

As an example you can use, here is a link to a Sheet I created with a handful of words that might be overused or vague or weak:

Sample Word List — Google Sheet link

Using Writer’s Highlighter

Now that you have a word list, you can use the Writer’s Highlighter add-on to scan your writing. Here’s how: 

  • Start by opening up a Google Document that has your writing you are wanting to edit.
  • Next click «Add-ons» in the top menu bar.
  • Click on «Writer’s Highlighter» from the drop-down menu, then choose «Start».
  • The Writer’s Highlighter add-on will open as a panel on the right side of your document.

 Spreadsheet Settings

In the «Spreadsheet Settings» section you will select the word list to use: 

Spreadsheet settings

  • In the «Spreadsheet link» box paste in the link to your word list Sheet (copied earlier).
  • The «Sheet name» box will default to the first sheet in your spreadsheet, but can be changed if needed.
  • Similarly, the «Sheet column» box will default to the first column in your spreadsheet, but can be changed if you want to use a word list from a different column.

Highlight Settings

In the next section you will choose how the matching words in your document will be formatted. 

Highlight settings screenshot

  • You can choose to have the matching words «Bold», «Italic», «Underline», and/or «Strikethrough».
  • If you want to highlight behind the words, check the «Highlight color» box and pick a color below.
  • If you want to change the font color of the words, check the «Text color» box and pick a color below.
  • An example of what your matching words will look like will be displayed.

Other Settings

In this next section you can adjust some settings for matching your words. 

Other Settings screenshot

  • Check «Ignore case» to match the words regardless of upper or lower case.
  • Check «Whole words only» to avoid matching just a portion of a word, such as finding «just» inside of «justified».
  • Check «Use wildcard» and select the symbol you wish to use to match words that fit a pattern, such as «*ly» to match any word that ends in a «ly» (such as an adverb).
  • Check «Run continuously» if you want the add-on to search for matches as you type. Note: this can slow down your computer.
  • Check «Save settings» to keep all your selections for the next time you open the add-on.

Run the Search! 

Highlight button screenshot

  • Finally, you can click on the «Highlight» button to search your document for matches to your word list, and to highlight the words accordingly.
  • You can also use «Highlight selection» to scan just the portion of the document your have selected, rather than the entire document.
  • If needed, use the «Clear all» or «Clear selection» buttons to reset the highlighting.

"George Washington Report" sample highlighting screenshot

Viewing Document Statistics 

In addition to highlighting words from your word list, the add-on can do some other helpful tasks. One feature to is view a page full of useful statistics about your writing. Simply click on the «View stats» button to see this report.

The «Document Stats» report includes: 

  • Word count — Totals for characters, words, sentences, paragraphs, and more.
  • Readability — Multiple scores for grade level, reading level, and more.
  • Word list — All of the words used, in order from most to least used in this document
  • Sentence list — A list of all the sentences with their lengths in words, with the option to color code by length

Document Stats screenshot

Highlighting Sentences by Length

Finally, you can also use this add-on to highlight all of the sentences in your document with colors based on their length. Shorter sentences are colored darker (blues and greens) and longer sentences are colored lighter (yellows, etc.). To see this just click the «Highlight sentences» button.

Highlighting Sentences by Length screenshot

cross posted at www.controlaltachieve.com

Eric Curts is an education trainer and consultant with over 20 years’ experience throughout the U.S. He is an authorized Google Education Trainer and a Google Certified Innovator. Read his blog at www.controlaltachieve.com and follow him on Google+ and @ericcurts on Twitter.

Tools and ideas to transform education. Sign up below.

Tags

Most Popular

  1. 01-13-2021, 07:51 AM


    #1

    rayted is offline


    Forum Contributor


    Highlight words from word list macro please

    Hi all,

    I have no idea how to write a macro and hope someone can help with the followign.

    I have a list of words in cell A1 example:

    test, tested, participant, new, help, helper

    and I have lots of comments in cell B1 to B1000. How do I write a macro/way of highlighting words in red font in cell B1 to B1000 which are from Cell A1? Any help appreciated. thank you!!

    Thanks,

    R.



  2. 01-13-2021, 08:53 AM


    #2

    Re: Highlight words from word list macro please

    a quick and simple nonMacro solution is to put your data in a Table and Filter it. in the filtered column you can put things like «Test*» or «*test*» which will do the same thing as a macro. Once your results are displayed, you can color as you like.


  3. 01-13-2021, 08:53 AM


    #3

    Re: Highlight words from word list macro please


  4. 01-13-2021, 08:56 AM


    #4

    Re: Highlight words from word list macro please

    Last edited by Mumps1; 01-13-2021 at 09:00 AM.

    You can say «THANK YOU» for help received by clicking the Star symbol at the bottom left of the helper’s post.
    Practice makes perfect. I’m very far from perfect so I’m still practising.


  5. 01-13-2021, 09:09 AM


    #5

    Re: Highlight words from word list macro please


Понравилась статья? Поделить с друзьями:
  • Highlight word from text
  • Highlight the spoken word
  • History of word expressions
  • Highlight the misspelled word
  • History of word classes