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")
WordApp.Documents.Add
Dim wordrange As Word.Range
Set wordrange = WordApp.ActiveDocument.Range(0, 0)
wordrange.Text = TextStr
WordApp.Visible = True
WordApp.Activate
wordrange.CheckSpelling , , True
SpellCheck = wordrange.Text
wordrange.Text = ""
WordApp.Documents.Close (False)
WordApp.Quit
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 |
|