Important alert: (current site time 7/16/2013 4:10:16 AM EDT)
 

VB icon

Spell Checker (uses MS Word)

Email
Submitted on: 5/28/1999
By: T. Heinel 
Level: Not Given
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 32264
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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
'
' 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.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1904&lngWId=1'for details.'**************************************

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
5/28/1999 2:17:00 AMT. Heinel

I forgot to mention that on the VB menu you have to press Project / References and select Microsoft Word Object Library.
(If this comment was disrespectful, please report it.)

 
5/29/1999 6:47:00 PMJamie

If you wrote a word processor and you decided to sell it and it used MS Word's spell checker would that be legal?
(If this comment was disrespectful, please report it.)

 
5/29/1999 11:04:00 PMWilliam M.

You saved my butt! I've been delaying a project
that asked to add a spell checker to an application
because I wasn't too familiar with how to incorporate
this feature using Word. Thanks alot!!
(I tested it and it works great! I made it a function
then called it on the 'lost_focus' event, passing it the
text and the form. The function call looks like this:
Text1.text = SpellCheck(Tex1.text,Me)
(If this comment was disrespectful, please report it.)

 
6/1/1999 6:48:00 AMRitesh Patel

Excellent! - Works very smoothly..
Thanx alot...
(If this comment was disrespectful, please report it.)

 
6/1/1999 9:16:00 AMJenn

I have a quick question. How would I do a spell check on a text box with
MultiLine set to true. The spell check works fine but once it fixes a misspelled
word, it doesn't keep the formatting of the text box. (loses any tabs or entering to create a new paragraph that you did)

I would appreciate any help you can give.
Thanks
(If this comment was disrespectful, please report it.)

 
6/7/1999 3:10:00 PMNick B

Very useful code to make into a OCX, only problem is Microsoft Word opens and shows. Anyone know of how to prevent it from showing for that breif moment?
(If this comment was disrespectful, please report it.)

 
6/14/1999 9:13:00 PMSwu

yeah I agree with Nick. Can I just modify any option that hidden the boxes open by MS WORD when I execute SpellCheck() ?
Thank a lot!!!
(If this comment was disrespectful, please report it.)

 
6/24/1999 1:43:00 PMSF

Works greate but I keep losing my text in the text box. I am using a richText text box.
Thanks SF
(If this comment was disrespectful, please report it.)

 
6/24/1999 8:44:00 PMTheothernerd

I hate to be rude, but this same code is in the Learning Visual BAsic CD that comes with Vb 5 learning edition. It is also much easier to understand for those who aren't experts at VB! So try not to compliment him so much.
(If this comment was disrespectful, please report it.)

 
6/26/1999 7:04:00 AMccjx


(If this comment was disrespectful, please report it.)

 
7/18/1999 5:44:00 PMxjcc

Heh heh heh... I am the evil ccjx from another dimension, and you will all die! By the way, you ppl are smart, I tried using the marquee tag and it freaked out on me!
(If this comment was disrespectful, please report it.)

 
1/3/2000 3:00:18 PMgr33n

Has anyone run into a a problem using this with a multi line text box? I'm haven't trouble with it. It returns the string as one line with return characters in it. Anyone have a clue how to get it to return in multi line?
(If this comment was disrespectful, please report it.)

 
1/4/2000 6:51:02 AMBurbble

Hmm it doesn't work. I know why it doesn't work... I don't have word! But is there some way to make a spell checker without word? just make one plain from scratch? It would be hard putting in all the words, but it would be cool. And um, why are you taking the code from Microsoft's copyrighted CD and saying it's your own...
(If this comment was disrespectful, please report it.)

 
1/4/2000 6:52:53 AMRating Guy

Yep this code is from da CD... What rating should it get...
(If this comment was disrespectful, please report it.)

 
1/24/2000 5:10:03 AMAdrian Cantrill

good code, also been delaying a project , but i really need this to work on a multiline text box without returning one long line with no formatting info. Anyone any idead
(If this comment was disrespectful, please report it.)

 
4/26/2000 1:04:14 PMPrasad

Simple, easy but brilliant code ! Thanks for saving our R&D time !
(If this comment was disrespectful, please report it.)

 
4/16/2001 6:08:12 PMMad Programmer

Could save your sometime by early binding.
Dim objMsWord As NEW Word.Application
'Then you do not need to use CreateObject, Instead use
(If this comment was disrespectful, please report it.)

 
6/25/2004 6:57:41 AM

have a quick question. How would I do
a spell check on a text box with

MultiLine set to true and Bold set to true and underlie. The spell
check works fine but once it fixes a
misspelled
word, it doesn't keep the
formatting of the text box. (loses any
tabs or entering to create a new
paragraph that you did)

I would
appreciate any help you can
give.
Thanks
saravanan

(If this comment was disrespectful, please report it.)

 
11/11/2004 4:06:48 PM

http://support.microsoft.com/default.aspx?scid=kb;en-us;243844
This article shows how to do the same thing and it will not loose the formatting. Word will flas on your screen though.
(If this comment was disrespectful, please report it.)

 
11/11/2004 4:07:33 PM

http://support.microsoft.com/default.aspx?scid=kb;en-us;243844
This article shows how to do the same thing and it will not loose the formatting. Word will flash on your screen though.
(If this comment was disrespectful, please report it.)

 
5/16/2005 7:14:46 AM

i want how to check for the pdf to doc
in quality checking software prepare the in vb

(If this comment was disrespectful, please report it.)

 
5/16/2005 7:16:32 AM

i want a software for quality checking for pdf to doc (qc report )
(If this comment was disrespectful, please report it.)

 

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.