VB icon

Automation of the Word Spell Checker

Email
Submitted on: 1/9/2015 10:06:00 AM
By: John Edward Colman (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages)
Views: 2785
 
     To help out my Dutch friend Frederik who needed to spell check in various languages, I designed this simple example. To adapt it to use a particular dictionary, supply the dictionary path as an option like so: w1.CheckSpelling(Text1.Text,"c:\path\MyDic.DIC)
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Automation of the Word Spell Checker
'**************************************
No Windows API.
Create a form with a TextBox CommandButton and ListBox.
Also include the Word library by selecting these menu options:
 Project > References:
 and checking "Microsoft Word 8.0 Object Library".
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Automation of the Word Spell Checker
' Description:To help out my Dutch friend Frederik who needed to spell check in various languages, I designed this simple example.
To adapt it to use a particular dictionary, supply the dictionary path as an option like so:
 w1.CheckSpelling(Text1.Text,"c:\path\MyDic.DIC)
' By: John Edward Colman (from psc cd)
'
' Inputs:Works better if you type one word at a time.
Of course, you'll write you code to automate this.
'
' Returns:Tells you if the spelling is good or a list of suggestions if not.
'
' Assumes:You'll need to own a fairly recent copy of Word. I used Word 97.
'
' Side Effects:Lot's of votes I hope!
'**************************************

Option Explicit
'Create a reference to the Word Automation Object
Dim w1 As Word.Application
Private Sub Command1_Click()
Dim I As Variant
'Empty the list box
List1.Clear
'Check the spelling of the word...
'If not in dictionary, fill a list box with suggestions
If w1.CheckSpelling(Text1.Text) = False Then
Beep
For Each I In w1.GetSpellingSuggestions(Text1.Text)
List1.AddItem I
Next
If List1.ListCount = 0 Then
List1.AddItem "No suggestions"
End If
Else
List1.AddItem "Spelling Correct"
End If
End Sub
Private Sub Form_Load()
'Open a new instance of Word
Set w1 = New Word.Application
'Create a new document (necessary)
w1.Application.Documents.Add
'Disable the following line if you don't want to see Word
w1.Visible = True
End Sub
Private Sub Form_Terminate()
'Quit, ignoring changes
w1.Quit False
Set w1 = Nothing
End Sub


Other 6 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 Intermediate 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.