VB icon

Spell Checker (uses MS Word)

Email
Submitted on: 1/2/2015 7:44:00 AM
By: T. Heinel (from psc cd)  
Level: Not Given
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 1691
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Spell Checker (uses MS Word)
' Description: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.
' By: T. Heinel (from psc cd)
'
' Returns:The code automatically replaces the original text of the message box with the corrected text.
'
' Assumes:Just create the text box and command button listed in the 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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.