O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required