Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoking Wor'ds spellcheck from within VB 6 1

Status
Not open for further replies.

gaus

Programmer
Feb 5, 2001
92
US
Does anybody know how this is done? I believe I have the necessary objects. I am passing an incorrectly spelled word to the sub, and invoking the checkspelling method. I get no errors, but it doesn;t seem to actually be checking the spelling.
Thanks,
Gary

In Declarations:
Private m_objWD as Word.Application

In sub:
Set m_objWD = CreateObject("Word.Application") m_objWD.CheckSpelling (txtWord.Text)
 
This is a very basic spell checker function, but it works with VB as well as asp pages:

Function SpellChecker(TextValue)
Dim objWordobject
Dim objDocobject
Dim strReturnValue
'Create a new instance of word Application
Set objWordobject = CreateObject("Word.Application")
objWordobject.WindowState = 2
objWordobject.Visible = True
'Create a new instance of Document
Set objDocobject = objWordobject.Documents.Add
objDocobject.Content = TextValue
objDocobject.CheckSpelling
'Return spell check completed text data
strReturnValue = objDocobject.Content
'Close Word Document
objDocobject.Close False
'Set Document To nothing
Set objDocobject = Nothing
'Quit Word
objWordobject.Application.Quit True
'Set word object To nothing
Set objWordobject = Nothing
SpellChecker = strReturnValue

MsgBox "Spell check is complete.", vbOKOnly, "Spell Check"
End Function

Mark
 
Mark,
How do you invoke that spell checker? And can it be invoked by a command button?
 
This is great - thanks!!
I was wondering if one could can call spell check without interacting with it, just to see if there is some property one can check to indicate a word is not in the dictionary, then give them the opportunity to correct the spelling on their own.
Is that even possible?
Thanks much,
Gary
 
One thing I noticed though. When I call the function and assign it to the variable (the same one as is being passed in order to replace it with the corrected spelling), it tacks on some strange ASCII char on the end of the word. Any ideas on how to avoid that?
Thanks again,
Gary
 
Gary,

Word is apparently tacking on an extra return character--maybe to assert the end of the document.

This will show how to use (Pinan) the SpellChecker as well as how can strip it out :

Private Sub cmdSpell()
Dim strTest As String
' Could also use contents of a Textbox
strTest = "test spel checker"
MsgBox strTest & " - Length:" & Len(strTest)
strTest = SpellChecker(strTest)
If Right(strTest, 1) = Chr(13) Then
strTest = Left(strTest, Len(strTest) - 1)
End If
MsgBox strTest & " - Length:" & Len(strTest)
End Sub


Mark
 
That's a good thought. I already unconditionally started grabbing all of the left char (less that last one) via Len and Left functions, and it works fine. But, I think the IF approach is better, just in case one come thru without that character (unlikely though). Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top