Word

Color Certain Words for Spell Checking

Ease of Use

Easy

Version tested with

2003 

Submitted by:

Jacob Hilderbrand

Description:

Changes font color of pre-defined often wrongly used words. 

Discussion:

While Word has a great spell checker, we may often type the wrong word, such as typing "our" instead of "out" or "or" instead of "of". This macro provides an alternative to the grammar checker. 

Code:

instructions for use

			

Option Explicit Sub SpellChecker2() Dim WordCol As Collection Dim i As Long Dim StartLine As Long Dim StartCol As Long Set WordCol = New Collection 'Add as many words here as you would like. WordCol.Add "our" WordCol.Add "out" WordCol.Add "of" WordCol.Add "or" For i = 1 To WordCol.Count StartLine = 0 StartCol = 0 Do Selection.Find.ClearFormatting With Selection.Find .Text = WordCol(i) .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = True End With Selection.Find.Execute If Selection.Range.Text = WordCol(i) Then If StartLine = 0 Then StartLine = Selection.Range.Information(wdFirstCharacterLineNumber) StartCol = Selection.Range.Information(wdFirstCharacterColumnNumber) Selection.Range.Font.Color = wdColorRed Else If StartLine <> Selection.Range.Information(wdFirstCharacterLineNumber) Or _ StartCol <> Selection.Range.Information(wdFirstCharacterColumnNumber) Then Selection.Range.Font.Color = wdColorRed Else Exit Do End If End If End If Loop Next i Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst End Sub

How to use:

  1. Open Word.
  2. Alt + F11 to open the VBE.
  3. From the Project Explorer select either ThisDocument of Normal depending on where you want to put the code.
  4. Insert | Module.
  5. Paste the code in the Code Window that opens to the right.
  6. Close the VBE (Alt + Q or press the X in the top-right corner).
 

Test the code:

  1. Tools | Macro | Macros...
  2. Select SpellChecker2 and press Run.
  3. All the specified words will be colored Red, then just manually check these words to make sure they are really what you wanted to say.
 

Sample File:

Word Highlighter.ZIP 6.04KB 

Approved by mdmackillop


This entry has been viewed 213 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express