Microsoft

A Word macro that highlights and lists misspelled words

Susan Harkins shares a macro that will highlight all misspelled words and copy them to a new document to make them easy to find and correct.

Most of us correct misspelled words and grammar as we type or we use spell check before we print or distribute the document. Word's spell check isn't a substitute for a thorough proofreading, but it certainly helps - unless you want to highlight all of the misspelled words or create a list of them. Those are tasks, spell check can't do for you, but a macro can.

The following macro highlights misspelled words and copies those words to a new document:

Sub HighlightSpellErrors()
  'Highlight all misspelled words.
  'Copy all misspelled words to new document.
  Dim rng As Range
  Dim docSourse As Document
  Dim docNew As Document
  Set docSource = ActiveDocument
  Set docNew = Documents.Add
  For Each rng In docSource.SpellingErrors
    rng.Font.Color = wdColorRed
    rng.Font.Bold = True
    docNew.Range.InsertAfter rng.Text & vbCR
  Next
End Sub

In this case, the macro uses red and bold to make each misspelled word easy to find. You can customize the two rng.Font statements in the For loop to suit your needs. The macro won't save the new document with the list of misspelled words, but you can add that functionality if you need it.

To add the macro to your document, press [Alt]+[F11] to launch the Visual Basic Editor (VBE). Insert a module if necessary by choosing Module from the Insert menu. Then, add the above code into the module and save the module. (Don't try to copy and paste from this page, it won't work. Type the code or download the module.) As is, the macro evaluates the entire document; if you select a range, the macro will ignore it.

There are a number of ways to run the macro. For now, click the Developer tab and then click Macros in the Code group. Select HighlightSpellErrors and click Run. If you use this macro a lot or if you don't have access to the developer tab, add the macro to the Quick Access Toolbar (QAT). After running the macro, you will find any misspelled words highly visible in red and bold. In addition, you'll have a new (unsaved) document, with a list of misspelled words.

This macro does not run a spell check session.

Editor's note: This macro is presented as a learning tool that you can use as a basis for your own project. It should not be treated as a market-ready application.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

13 comments
Spitfire_Sysop
Spitfire_Sysop

Not sure what version you are using but mine underlines each misspelled word as I type them. This way I can correct as I go. Making a list could be nice, I suppose.

bkreamer
bkreamer

Line 5, docSourse should be docSource

ppg
ppg

The macro may be useful - possibly for a teacher or someone else who just wants to highlight spelling errors. However it is not very helpful if you want to correct the errors since when correct the word it is still red and bold so you would have to manually revert each word. To make it better I would suggest you use a format that you are not likely to use in you document - say red borders around the word and then create a second macro to remove all the highlighting

lwdunham
lwdunham

I noticed that the code within the article on this page is different than the code when you click the "download the module" link. That might be a reason the code doesn't work when you try to copy and past from the article. Just a heads up. :)

mig25jet
mig25jet

Can! Swiped over, ctrl + c, paste into wordpad, ctrl + c, paste into VBE. :-)

misceng
misceng

I am coming to believe that many articles are dictated to a PC and not proof read. This macro is unlikely to find the errors where a valid word is put in place of the correct one. I am fed up with reading "there" when it should be "their" or vice versa. Anyone can add a long list of similar follies.

grahamrice
grahamrice

The variables docSource and docNew need to be included in the Dim statement.

ssharkins
ssharkins

It's a feature you can disable. I don't know that the average user will find this macro useful as is -- It has a specialized purpose. I like it because it uses the SpellingErrors collection. Most people don't even know it exists, but it has great potential I think!

ssharkins
ssharkins

The download should match the code soon -- in the meantime, it's an easy fix. Just add the declarative statements for the two document variables: Dim docSource As Document Dim docNew As Document Or, comment out the Option Explicit statement at the top of the module, but I don't recommend you do that -- unless you're just experimenting with the code.

ssharkins
ssharkins

I do proof these pieces, a lot -- mistakes happen. If you found a mistake, and you'd like to point it out, I'll make sure it gets fixed quickly. That would be helpful.

ssharkins
ssharkins

I'll add those -- but it will work with Option Explicit disabled, that's why I didn't catch this myself.

Editor's Picks