Microsoft Access Office VB VBA Help and Examples

Borrow Word Spell Check From Access

This example shows how to check a string for spelling and popup the word spelling dialog if we need to correct it. First add a reference to the version of word you are running. Then paste the following code into a new module and you can call it from anywhere. This module will call it's own window of word, create a new document, paste the supplied text to it, and then check the text for spelling, using words dialogs. Once finished the function returns the corrected text.

Public Function SpellCheck(TextStr As String) As String
     Dim WordApp As Word.Application
     Set WordApp = CreateObject("Word.Application")
     Dim wordrange As Word.Range
     Set wordrange = WordApp.ActiveDocument.Range(0, 0)
     wordrange.Text = TextStr
     WordApp.Visible = True
     wordrange.CheckSpelling , , True
     SpellCheck = wordrange.Text
     wordrange.Text = ""
     WordApp.Documents.Close (False)
     Set WordApp = Nothing
End Function

    Here's an example of how to call this function

Private Sub test()
     Dim ChkStr As String
     ChkStr = "John wias here"
     ChkStr = SpellCheck(ChkStr)
End Sub
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.