-1

I have a VB6.0 project with MDI parent and child form. Now I need to check spelling and grammar in few text boxes on that child form.

Please help with code example.

4

1 回答 1

3

You could license a professional ActiveX component like Tachyon's spellchecker. I found a list here.

If you could demand Microsoft Word installed on the client machine as prerequisit, you could use Word's spell checker:

Dim objWord As Object
Dim objDoc  As Object

Dim strResult As String

' // Create a new instance of word Application

Set objWord = CreateObject("word.Application")

Select Case objWord.Version
   ' // Office 2000
   Case "9.0"
      Set objDoc = objWord.Documents.Add(, , 1, True)

   ' // Office XP
   Case "10.0"
      Set objDoc = objWord.Documents.Add(, , 1, True)

   ' // Office 97
   Case Else ' Office 97
      Set objDoc = objWord.Documents.Add

End Select

objDoc.Content = Text1.Text
objDoc.CheckSpelling

strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)

If Text1.Text = strResult Then
    ' // There were no spelling errors, so give the user a
    ' // visual signal that something happened

    MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
End If

You can find another good example in this article about how to call the MS Word Spell Checker.

于 2008-10-18T10:42:38.760 回答