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

VB icon

Word Magic

Email
Submitted on: 6/10/1999
By: Richard Lowe 
Level: Not Given
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 34379
 
     This program allows simple desktop access the the Microsoft Word spelling and thesaurus engine using OLE Automation. You can Spell Check, Produce Anangrams, use the Thesaurus and look up the meaning of words. THIS IS A COMPLETE WORKING APPLICATION
 
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: Word Magic
' Description:This program allows simple desktop access the the Microsoft Word spelling and thesaurus engine using OLE Automation.
You can Spell Check, Produce Anangrams, use the Thesaurus and look up the meaning of words. THIS IS A COMPLETE WORKING APPLICATION
' By: Richard Lowe
'
' Assumes:Must have Microsoft Word Installed
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2043&lngWId=1'for details.'**************************************

'===========================================================================
'Start a new project
'add a ComboBox named cboInput
'add a ListBox named lstDisplay
'add a Command Button named cmdHelp caption Help
'add a Command Button named cmdExit caption Exit
'add 4 Command Buttons (command array) named 
'cmdAction(0)	caption Spelling
'cmdAction(1)	caption Wildcard
'cmdAction(2)	caption Anagarm
'cmdAction(3)	Caption Lookup
'In the Project/References menu option tick the reference for
'Microsoft Word 8.0 Object Library
'===========================================================================
'paste the following code
Option Explicit
'============================================================
'== Author : Richard Lowe
'== Date : June 99
'== Contact : riklowe@hotmail.com
'============================================================
'== Desciption
'==
'== This program enable quick and easy desktop access to
'== the Microsoft Word spelling and thesaurus engine.
'==
'============================================================
'== Version History
'============================================================
'== 1.0 06-Jun-99 RL Initial Release. Spelling Only
'== 1.1 07-Jun-99 RL Added Widcard, Anagram and Lookup
'== 1.2 08-Jun-99 RL Added Help 
'============================================================
'------------------------------------------------------------
'Define constants
'------------------------------------------------------------
Const HeightLimit = 5000
Const WidthLimit = 5640
'------------------------------------------------------------
'Dimension variables
'------------------------------------------------------------
Dim objMsWord As Word.Application
Dim SugList As SpellingSuggestions
Dim sug As SpellingSuggestion
Dim synInfo As SynonymInfo
Dim synList As Variant
Dim AntList As Variant
Private Sub cmdAction_Click(Index As Integer)
'------------------------------------------------------------
' dimension local variables
'------------------------------------------------------------
Dim strTemp As String
Dim blnRet As Boolean
Dim iCount As Integer
'------------------------------------------------------------
' Asign an error handler
'------------------------------------------------------------
On Error GoTo eh_Trap:
'------------------------------------------------------------
' If cboInput has changed, add it as an entry to the list
'------------------------------------------------------------
 If cboInput.List(0) <> cboInput Then
cboInput.AddItem cboInput, 0
 End If
 
'------------------------------------------------------------
'Assign the objMsWord object reference to the Word application
'------------------------------------------------------------
 Set objMsWord = New Word.Application
 
'------------------------------------------------------------
'Due to a bug, you have to open a file to use GetSpellingSuggestions
'This is documented in Q169545 on microsoft knowledge base
'------------------------------------------------------------
 objMsWord.WordBasic.FileNew'open a doc
 objMsWord.Visible = False'hide the doc
 
'------------------------------------------------------------
' clear display area
'------------------------------------------------------------
 lstDisplay.Clear
 
'------------------------------------------------------------
' select which button has been pressed
'------------------------------------------------------------
 Select Case Index
 Case 0
'------------------------------------------------------------
'Spelling
'------------------------------------------------------------
blnRet = objMsWord.CheckSpelling(cboInput)
'------------------------------------------------------------
'if incorrectly spelt, check for suggestions. Iterate and display
'------------------------------------------------------------
If blnRet = True Then
 lstDisplay.AddItem "OK"
Else
 Set SugList = objMsWord.GetSpellingSuggestions(cboInput, _
 SuggestionMode:=wdSpelling)
 
 If SugList.Count = 0 Then
lstDisplay.AddItem "No suggestions"
 Else
For Each sug In SugList
 lstDisplay.AddItem sug.Name
Next sug
 End If
 
End If
 Case 1
'------------------------------------------------------------
'WildCard
'------------------------------------------------------------
Set SugList = objMsWord.Application.GetSpellingSuggestions(cboInput, _
SuggestionMode:=wdWildcard)
'------------------------------------------------------------
'If entries found, Iterate and display
'------------------------------------------------------------
If SugList.Count = 0 Then
 lstDisplay.AddItem "No suggestions"
Else
 For Each sug In SugList
lstDisplay.AddItem sug.Name
 Next sug
 
End If
 Case 2
'------------------------------------------------------------
'Anagram
'------------------------------------------------------------
Set SugList = objMsWord.GetSpellingSuggestions(cboInput, _
SuggestionMode:=wdAnagram)
'------------------------------------------------------------
'If entries found, Iterate and display
'------------------------------------------------------------
If SugList.Count = 0 Then
 lstDisplay.AddItem "No suggestions"
Else
 For Each sug In SugList
lstDisplay.AddItem sug.Name
 Next sug
End If
 Case 3
'------------------------------------------------------------
'Lookup
'------------------------------------------------------------
'------------------------------------------------------------
'Assign the synInfo object reference to the Word Synonym Information
'------------------------------------------------------------
Set synInfo = objMsWord.SynonymInfo(cboInput)
lstDisplay.AddItem "--- MEANING ---"
'------------------------------------------------------------
'If entries found, Iterate and display
'------------------------------------------------------------
If synInfo.MeaningCount >= 2 Then
 synList = synInfo.MeaningList
 For iCount = 1 To UBound(synList)
lstDisplay.AddItem synList(iCount)
 Next iCount
Else
 lstDisplay.AddItem "None"
End If
lstDisplay.AddItem "--- SYNONYM ---"
'------------------------------------------------------------
'If entries found, Iterate and display
'------------------------------------------------------------
If synInfo.MeaningCount >= 2 Then
 synList = synInfo.SynonymList(2)
 For iCount = 1 To UBound(synList)
lstDisplay.AddItem synList(iCount)
 Next iCount
Else
 lstDisplay.AddItem "None"
End If
Set synInfo = Nothing
 End Select
 
'------------------------------------------------------------
'Clean exit point
'------------------------------------------------------------
eh_exit:
 objMsWord.Quit
 Set objMsWord = Nothing
 cboInput.SetFocus
Exit Sub
'------------------------------------------------------------
'Error Handler
'------------------------------------------------------------
eh_Trap:
 
 lstDisplay.AddItem Err & vbTab & Error$
 Resume eh_exit:
 
End Sub
Private Sub cmdExit_Click()
 Unload Me
End Sub
Private Sub cmdHelp_Click()
'------------------------------------------------------------
'Display help information in the viewing area
'------------------------------------------------------------
 lstDisplay.Clear
 
 lstDisplay.AddItem "Spelling "
 lstDisplay.AddItem "Enter a word into the box above, press 'Spelling'"
 lstDisplay.AddItem "Correctly spelt words will display 'OK'"
 lstDisplay.AddItem "Incorrectly spelt words will display a list of "
 lstDisplay.AddItem "choices that most closely match the word"
 lstDisplay.AddItem " "
 lstDisplay.AddItem "Wildcard "
 lstDisplay.AddItem "Enter a word into the box above, press 'Wildcard'"
 lstDisplay.AddItem "Use a ? to indicate an unkown letter"
 lstDisplay.AddItem "Use a * to indicate muliple unkown letters"
 lstDisplay.AddItem "Examples (?) - Cl?se, Un?no?n "
 lstDisplay.AddItem "Examples (*) - Cl*, C*e"
 lstDisplay.AddItem " "
 lstDisplay.AddItem "Anangram "
 lstDisplay.AddItem "Enter a word into the box above, press 'Anagram'"
 lstDisplay.AddItem "The program will find all words in the "
 lstDisplay.AddItem "dictionary containing those letters "
 lstDisplay.AddItem " "
 lstDisplay.AddItem "Lookup "
 lstDisplay.AddItem "Enter a word into the box above, press 'Lookup'"
 lstDisplay.AddItem "The program will find the meaning and synonym "
 lstDisplay.AddItem "for the word from the dictionary "
 lstDisplay.AddItem " "
 lstDisplay.AddItem "General "
 lstDisplay.AddItem "Double click on an entry in this list box"
 lstDisplay.AddItem "and it will be transfered to the box above."
 lstDisplay.AddItem "Use the up and down arrows on the keyboard "
 lstDisplay.AddItem "or select the arrow at the right hand side "
 lstDisplay.AddItem "of the above box, to scroll through all of "
 lstDisplay.AddItem "the word you have entered."
 lstDisplay.AddItem ""
 lstDisplay.AddItem "Please e-mail any comments / suggestions to"
 lstDisplay.AddItem "me - It's great to get feedback."
 lstDisplay.AddItem "My e-mail address is riklowe@hotmail.com"
 lstDisplay.AddItem ""
 
End Sub
Private Sub Form_Load()
 cboInput.Clear
 
End Sub
Private Sub Form_Resize()
'------------------------------------------------------------
'Do not let the screen size get to small, so that the button
'are always visible
'------------------------------------------------------------
 Select Case Me.WindowState
 Case vbNormal
If Me.Height < HeightLimit Then
 Me.Height = HeightLimit
End If
lstDisplay.Height = Me.Height - 1000
Me.Width = WidthLimit
 Case Else
 End Select
 
End Sub
Private Sub lstDisplay_DblClick()
'------------------------------------------------------------
'Move entry from listbox into combo box
'------------------------------------------------------------
 
 cboInput.AddItem lstDisplay, 0
 cboInput.ListIndex = 0
 lstDisplay.Clear
 cboInput.SetFocus
 
End Sub


Other 3 submission(s) by this author

 


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

6/10/1999 10:22:00 AMDMan

Best Spellchecker I seen on this site - great code - the way it should be done
(If this comment was disrespectful, please report it.)

 
7/2/1999 9:24:00 PMVbmaster

Yes, making applications that needs M$ Word to be installed on the system, that's just GREAT!
(If this comment was disrespectful, please report it.)

 
7/6/1999 11:13:00 AMPauline

hello there..... it's really great to have all these source code made available... i have just view the word magic program and its really great... there is one thing that i might need to ask your favour from... im currently is still studying and so im using VB to develop my application for my project.. i am having difficulties in one of the prgram that im doing that is e-mail and FTP... i was just wondering if u could help me out here as i am stuck half way... is there any available source code for mail, chatting as well as FTP..
i really appreciate it if u could reply me back...
thank you...
sorry for all the trouble that i might have caused....:)
(If this comment was disrespectful, please report it.)

 
7/7/1999 1:10:00 PMjd

Hey, I don't have Microsoft Word 8.0 Object Library, please send it to me or send me the project thanks.

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

 
7/10/1999 10:11:00 AMRobert Sanders

Wow, this is really cool. It's almost exactly what I've been looking for. Most other demo's use word's popup spell checking box.

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

 
7/22/1999 10:35:00 PMSheepy

Its gonna take me ages to work out how this works!
(If this comment was disrespectful, please report it.)

 
8/4/1999 12:44:00 PMSulayman Khan

I think your program is great... however i have problem when i run it. You see, when the program loads the dictionary from word... my program crashes. What should I do?
(If this comment was disrespectful, please report it.)

 
11/29/1999 5:01:00 AMMicha

Nice code, works like a charm.
However, it would be more useful if
you can check the text from a textbox
in stead of a combo/listbox.
I've tried to do it myself, but to no
avail. Can you (or anyone else) tell
me how? Thnx.
(If this comment was disrespectful, please report it.)

 
1/3/2000 3:14:00 PMgr33n

I can't seem to get this to work... Could it be that I am running WinNT?
I keep getting an error on this line "Dim objMsWord As Word.Application" work isn't an option in my VB6.0

Anyone have a clue how to fix it or is it a problem with WinNT.. I didn't install word first.. Could that be the problem??
(If this comment was disrespectful, please report it.)

 
1/6/2000 10:39:49 PMpantana

Nice. I noticed that if your using the MS Word 9.0 Object library, the anagram and wildcard don't work.
(If this comment was disrespectful, please report it.)

 
1/6/2000 10:41:25 PMpantana

Also, I was wondering, where do you find all the info on the parameters for various MS dll's.
(If this comment was disrespectful, please report it.)

 
2/8/2000 5:17:47 PMAPERSON

Is what you need to do, is make a spell checker for people that don't have MS Word, I do but I have beeen trying to make one for my friend cause he doesn't. I don't like your code because of useing ms word
(If this comment was disrespectful, please report it.)

 
2/9/2000 3:37:43 AMRichard Lowe

APERSON - If you don't like my code - then don't use it !!!! Just because you have a problem with Microsoft dosn't mean everyone else does. Who do you think wrote Visual Basic.

GROW UP and get a grammer checker while your at it - I think MS Word has one you could use !!!
(If this comment was disrespectful, please report it.)

 
7/29/2000 3:51:13 AMYang Zeqi

You really saved my day! Keep up the good work man!
(If this comment was disrespectful, please report it.)

 
8/2/2000 3:50:28 PMDave

A delightful expose' (as it were) of Word automation!
(If this comment was disrespectful, please report it.)

 
11/29/2000 11:13:50 PMTroy J

I am running WinNT 4, SP6a, Word2k, same problem as the above guy using WinNT.

Error "User Defined Type Not Defined" on this line:
Dim objMsWord As Word.Application

I do have the reference set, etc... Anyone have any ideas?

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

 
4/28/2002 1:06:51 PMDavid

ATTN: Richard Lowe

I think your script would be great - If I could run it -.

Do you have any solution for Word XP users? I can't seem to find Word in the reference box.
(If this comment was disrespectful, please report it.)

 
10/8/2002 7:34:54 PM~ : . Jeff ''Capes'' . : ~

only the spell check does work with object lib. 9.0
Unless: 5 from me!
(If this comment was disrespectful, please report it.)

 
12/14/2002 7:36:44 PMDanny J.

Can someone make this really easy?
(If this comment was disrespectful, please report it.)

 
2/11/2003 8:32:35 PM

Great code ! 5 stars
(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.