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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spell checker for dynamic text box

Status
Not open for further replies.

rich99730

Technical User
May 20, 2008
8
US
Hi
I have found the following code through hours of researching for spell checking a text box. The following event happens on the click event on my user form.

Here is the problem.
1. So far what I have found is if you miss spell words, upon the click event if the word is spelled wrong it offers suggestions as ms word does. If the word contains a number the following code allows the word through?? I Found this on accident.

2. I am also trying to have the autocomplete function work on this same text box with no luck. for example when I type "janu" word normally offers "January" as its suggestion, which subsequently is what I want to happpen. Any help would be great

Public Function CheckSpelling(t As TextBox)
'SpellCheck Function
'taken from http://www.vbforums.com/showthread.php?t=246451On Error GoTo Err_Handler
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String

'Create a new instance of word Application
'Application.OleRequestPendingTimeout = 999999
Set objWord = CreateObject("word.Application")
objWord.Visible = False

Set objDoc = objWord.Documents.Add(, , 1, True)

objDoc.Content = t.Text
objDoc.CheckSpelling
objWord.Visible = False
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
'correct the carriage returns
strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))

If t.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spell check is complete!", vbInformation + vbOKOnly, "Spelling Complete"
End If

'Clean up
objDoc.Close False
Set objDoc = Nothing
objWord.Application.Quit True
Set objWord = Nothing

' Replace the selected text with the corrected text. It's important that
' this be done after the "Clean Up" because otherwise there are problems
' with the screen not repainting

t.Text = strResult

Exit Function
'in case user does not have word...
Err_Handler: MsgBox Err.Description & Chr(13) & Chr(13) & "Please note you must have Microsoft Word installed to utilize the spell check feature.", vbCritical, "Error #: " & Err.Number
End Function

Thank You
Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top