Tools Links Login

Spell Checker (uses MS Word)

This code uses OLE Automation to allow VB to open an instance of MS Word if the user has it on their system and spell check the contents of a text box. It could easily be modified to work with any control that has text on it. I would recommend better error control than the On Error statement listed here.

Original Author: T. Heinel

Assumptions

Just create the text box and command button listed in the code.

Returns

The code automatically replaces the original text of the message box with the corrected text.

Code

Private Sub cmdSpellCheck_Click()
  'On Error Resume Next 'Best to un-comment this while testing
  Dim objMsWord As Word.Application
  Dim strTemp As String
  Set objMsWord = CreateObject("Word.Application")
  objMsWord.WordBasic.FileNew
  objMsWord.WordBasic.Insert txtMessage.Text
  objMsWord.WordBasic.ToolsSpelling
  objMsWord.WordBasic.EditSelectAll
  objMsWord.WordBasic.SetDocumentVar "MyVar", objMsWord.WordBasic.Selection
  objMsWord.Visible = False ' Mostly prevents Word from being shown
  strTemp = objMsWord.WordBasic.GetDocumentVar("MyVar")
  txtMessage.Text = Left(strTemp, Len(strTemp) - 1)
  
  objMsWord.Documents.Close (0) ' Close file without saving
  objMsWord.Quit         ' Exit Word
  Set objMsWord = Nothing    ' Clear object memory
  frmMain.SetFocus        ' Return focus to Main form
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 165 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.