by John Edward Colman (7 Submissions)
Category: Microsoft Office Apps/VBA
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
To help out my Dutch friend Frederik who needed to spell check in various languages, I designed this simple example.
To adapt it to use a particular dictionary, supply the dictionary path as an option like so:
w1.CheckSpelling(Text1.Text,"c:\path\MyDic.DIC)
Inputs
Works better if you type one word at a time.
Of course, you'll write you code to automate this.
Assumes
You'll need to own a fairly recent copy of Word. I used Word 97.
Code Returns
Tells you if the spelling is good or a list of suggestions if not.
Side Effects
Lot's of votes I hope!
API DeclarationsNo Windows API.
Create a form with a TextBox CommandButton and ListBox.
Also include the Word library by selecting these menu options:
Project > References:
and checking "Microsoft Word 8.0 Object Library".
Option Explicit
'Create a reference to the Word Automation Object
Dim w1 As Word.Application
Private Sub Command1_Click()
Dim I As Variant
'Empty the list box
List1.Clear
'Check the spelling of the word...
'If not in dictionary, fill a list box with suggestions
If w1.CheckSpelling(Text1.Text) = False Then
Beep
For Each I In w1.GetSpellingSuggestions(Text1.Text)
List1.AddItem I
Next
If List1.ListCount = 0 Then
List1.AddItem "No suggestions"
End If
Else
List1.AddItem "Spelling Correct"
End If
End Sub
Private Sub Form_Load()
'Open a new instance of Word
Set w1 = New Word.Application
'Create a new document (necessary)
w1.Application.Documents.Add
'Disable the following line if you don't want to see Word
w1.Visible = True
End Sub
Private Sub Form_Terminate()
'Quit, ignoring changes
w1.Quit False
Set w1 = Nothing
End Sub