Advertisement
ASP_Volume3 Microsoft Office Apps/VBA #50626

Automation of the Word Spell Checker

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)

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine