Microsoft & .NETVisual BasicMake a Spell Checker

Make a Spell Checker content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Spell checking has always been one of MS Word’s greatest features, but now you to can include spell checking into your application with out increasing your file size.

This great example demonstrates how you can setup a spell check by opening Word, copying and pasting the text, spell check it and then close down Word.

Private Function FN_SpellCheck(strTextToVerify As String) _
  As Boolean
On Error GoTo FN_SpellCheckErr

Dim oWord As Object
Dim strSelection As String
Set oWord = CreateObject("Word.Basic")
With oWord
  ' done immediately before to minimize possibility of
  ' user interaction with the clipboard
  Clipboard.SetText strTextToVerify, vbCFRTF
  On Error Resume Next
  On Error GoTo 0
  strSelection = Clipboard.GetText(vbCFRTF)
  If Mid(strSelection, Len(strSelection), 1) = Chr(13) Then
    strSelection = Mid(strSelection, 1, Len(strSelection) - 1)
  End If

  If Len(strSelection) > 1 Then
    strTextToVerify = strSelection
    FN_SpellCheck = True
  End If
  .FileCloseAll 2
End With

Set oWord = Nothing

Exit Function

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories