Compiling Misspelled Words from Documents

Written by Allen Wyatt (last updated June 1, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Robert has a folder that has many documents in it. He would like a way to pull all the misspelled words from the documents and place those words in a new document.

Fortunately, Word makes this relatively easy through the use of a macro. This is because the spelling errors are accessible in VBA by examining the .SpellingError collection. Each item in this special collection represents a spelling error in the document.

With this in mind, the following macro shows how to pull together all the spelling errors from each document in a folder.

Sub CheckFolderForSpellErrors()
    'Copy all misspelled words in each document
    'from one directory to a new document.
    'Also lists all documents that have no spelling errors

    Dim cWords As New Collection
    Dim cDocs As New Collection
    Dim vItem As Variant
    Dim rng As Range
    Dim docSourse As Document
    Dim docNew As Document
    Dim vDirectory As String
    Dim vFile As String
    Dim bNoSpellingErrors As Boolean

    Application.ScreenUpdating = False

    vDirectory = "C:\MyFolder\"           ' Path to check

    ' Find first file to check
    vFile = Dir(vDirectory & "*.doc*")

    Do While vFile <> ""
        Documents.Open FileName:=vDirectory & vFile
        Set docSource = ActiveDocument

        If docSource.SpellingErrors.Count > 0 Then
            cWords.Add Item:="Spelling errors found in " & vFile & vbCrLf

            ' add each word to the collection
            For Each rng In docSource.SpellingErrors
                cWords.Add Item:=rng.Text & vbCrLf
            Next
        Else ' doc has no spelling errors
            bNoSpellingErrors = True
            cDocs.Add vFile & vbCrLf
        End If

        ActiveDocument.Close (wdDoNotSaveChanges)
        vFile = Dir
    Loop

    Set docNew = Documents.Add

    For Each vItem In cWords
        Selection.TypeText vItem
    Next

    If bNoSpellingErrors Then
        Selection.TypeText "These documents have no spelling errors." & vbCrLf

        For Each vItem In cDocs
            Selection.TypeText vItem & vbCrLf
        Next
    End If

    Application.ScreenUpdating = True
End Sub

The macro uses the Dir command to find any files in the specified folder (vDirectory variable) that end in some variant of "doc." Each of these files is loaded into Word, in turn. While loaded, the .SpellingErrors collection is checked to see if it contains any errors. If it does, then the text of the incorrectly spelled words is added to the cWords collection. If it doesn't, then the file name is added to the cDocs collection.

There is nothing special about either the cWords or the cDocs collections; they were created simply to hold whatever spelling errors and file names were discovered when examining the files. The macro could just as easily have used variable arrays in place of the collections.

There are a couple of things to keep in mind when running this macro. First, it can take quite a while to run, depending on the number of documents in the folder and the length of each of those documents. When I ran the macro, I did so on a folder that contained 9 documents averaging about 97 pages per document. It took just under 8 minutes for the macro to complete running, and while it was running I could do nothing else in Word. (In fact, you might easily wonder if your system is "hung.")

Another thing to keep in mind is that the output can be quite long and seem rather redundant. This is because misspelled words can appear multiple times in the .SpellingErrors collection. For instance, let's say you have a document that contains the word "Cftype," which is obviously flagged as being misspelled. If the word is used 30 times in the document, it will be flagged 30 times and therefore end up 30 times in the misspelling list. Although it is beyond the scope of this tip, you could modify the macro to check if a word was previously flagged as misspelled and then add it only if it is unique misspelling.

Note:

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 (13488) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

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. ...

MORE FROM ALLEN

Placing the First Two Words from the Following Page In the Footer

Headers and footers can be used for all sorts of information to help orient your document reader. In fact, Word provides ...

Discover More

Finding the Path to the Desktop

Figuring out where Windows places certain items (such as the user's desktop) can be a bit frustrating. Fortunately, there ...

Discover More

Calculating a Date Five Days before the First Business Day

Excel allows you to perform all sorts of calculations using dates. A good example of this is using a formula to figure ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Spelling Errors on Internet Addresses

Tired of Word marking Internet addresses as spelling errors? You can turn off this check by applying the steps in this tip.

Discover More

Checking Just the Selected Text

Having a hard time doing a spell check on just the portion of the document you've selected? This is apparently due to a ...

Discover More

Spell-Checking Abbreviations

Need to make sure that Word includes abbreviations when you check a document's spelling? Here's how to make sure that ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.