Spelling-Related Properties and Methods

The Document object has several members that relate to spelling and grammar:

CheckGrammar method

Begins a spelling and grammar check for the document and displays the Spelling and Grammar dialog box when errors are encountered.

CheckSpelling method and SpellingChecked property

This method begins a spellcheck for the document and displays the Spelling and Grammar dialog box when errors are encountered (with the Check Grammar checkbox cleared).

Once the CheckSpelling method has been executed (or if the user does a spellcheck), Word sets the SpellingChecked property to True. Subsequent calls to CheckSpelling will do nothing unless you first set the SpellingChecked property to False.

The SpellingErrors property

The SpellingErrors property returns the ProofreadingErrors collection, which contains Range objects that identify the words in the document that are considered spelling errors.

Note that any reference to this property triggers a behind-the-scenes spellcheck in order to fill the ProofreadingErrors collection (which can take some time). You can verify this simply by creating a new document, filling it with some text that contains some spelling errors and then executing the line:

Debug.Print ActiveDocument.SpellingErrors.Count

This will cause Word to do a behind-the-scenes spellcheck so Word can report the count of spelling errors.

By way of example, the program in Example 12-1 prints all of the spelling errors in the active document to a new document. ...

Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.