VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Spell Checker (uses MS Word)

by T. Heinel (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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.

Assumes
Just create the text box and command button listed in the code.
Code Returns
The code automatically replaces the original text of the message box with the corrected text.

Rate Spell Checker (uses MS Word)

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

Download this snippet    Add to My Saved Code

Spell Checker (uses MS Word) Comments

No comments have been posted about Spell Checker (uses MS Word). Why not be the first to post a comment about Spell Checker (uses MS Word).

Post your comment

Subject:
Message:
0/1000 characters