-
Re: VB - Spell Check a Textbox
Hello. I am trying to implement a spell check on my RichTextBox. When I copy and paste your code, it doesn't like these two lines:
App.OleRequestPendingTimeout = 999999
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
Any ideas why? Thanks for any help!
-
Re: VB - Spell Check a Textbox
Have you included the Reference to Word?
-
Re: VB - Spell Check a Textbox
Yes, I have added the Word reference, but do I need to put something like this at the top of my form?
Imports Word.??????
-
1 Attachment(s)
Re: VB - Spell Check a Textbox
No you don't need to do that (at least not in VB6). I've attached a working sample.
-
Re: VB - Spell Check a Textbox
I am using VB.NET. Do you know of any postings on spell checking in .NET?
-
Re: VB - Spell Check a Textbox
Hi!
Does anyone have any idea how to make the spell and grammar check multilanguage?
Thanks!
-
Re: VB - Spell Check a Textbox
Does Word do it? If so then it should be fairly easy. If not then....?
-
Re: VB - Spell Check a Textbox
-
Re: VB - Spell Check a Textbox
I tried it out and it does check in multiple languages. Ex: I typed Achtung by default it shows it as an incorrect spelling since the default language is English. If I select the word and right click , select the language as German it recognizes it as valid.
I don't know how to leverage this programatically. How do you tell word which language it should do the spelling and grammar check in?
Thanks!
jb
-
Re: VB - Spell Check a Textbox
Record a macro while doing what you just did and then add the "commands" to my code.
-
Re: VB - Spell Check a Textbox
Got it! This is what I got in the macro..
VB Code:
Sub SpellCheck()
'
' SpellCheck Macro
'
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.LanguageID = wdGerman
Selection.NoProofing = False
Application.CheckLanguage = False
End Sub
I'll try it out in the project.
Thank you! That was a great idea!
jb
-
Re: VB - Spell Check a Textbox
can i use that in my html editor?
-
Re: VB - Spell Check a Textbox
Quote:
Originally Posted by MartinLiss
3 When users try to use other applications while the spellchecker is in progress the screen gets confused and appears to crash.
Do you have a fix for this Martin?
Pretty annoying for the user because if they switch to another application and switch back it's frozen and they have to ctrl/alt/delete to end the application task.
-
Re: VB - Spell Check a Textbox
-
Re: VB - Spell Check a Textbox
Are you referring to this code?
Code:
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
' Correct the carriage returns
strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))
If Text1.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
End If
-
Re: VB - Spell Check a Textbox
I don't think I'm missing anything. This is code I'm using:
VB Code:
Public Function CheckSpelling(t As textbox)
'SpellCheck Function
'taken from [url]http://www.vbforums.com/showthread.php?t=246451[/url]
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
'Create a new instance of word Application
App.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
-
Re: VB - Spell Check a Textbox
Sorry but since I don't use VBA I can't help. Maybe user rike has some insight into the problem. If you do solve it please let me know.
-
Re: VB - Spell Check a Textbox
Ok - thanks anyway Martin.
-
Re: VB - Spell Check a Textbox
Sorry I was unable to find a fix for this.
-
Re: VB - Spell Check a Textbox
Alright, I'm using this code to check the spelling on a text box when it loses focus. The problem is that if I you want the "mispelled" word to remain and you choose "ignore", I get:
Runtime Error '5'
Invalid procedure call or argument
If you are running it from the editor (testing) you don't get this error...if you make an executable you get the error.
Please help.
-
Re: VB - Spell Check a Textbox
I just tried to reproduce your problem and I couldn't. If you attach your project I'll take a look at it.
-
Re: VB - Spell Check a Textbox
This code is wonderful and will meet my needs if I can get it to work. Using Word and Access 2003. The code runs well until the last line:
Comments.Text = strResult
where Comments is the name of the text box.
The message I get is:
Run-Time error '2115'
The macro or function set to the BeforeUpdate or Validation Rule property for this field is preventing the database from saving the data in the field.
There isn't any code associated with the BeforeUpdate or Validation Rule properties for the field.
OK, I kept trying and decided to use the code for a Function and change the OnKeyDown event for F7. When done this way, the error above is gone but when the text box is checked and corrected, Spell Check continues to the first record of the database and the first textbox on the form.
Just stepped through the code and it all runs. When it finishes, it seems that the regular spell check associated with F7 runs. How can I stop this from happening?
It seems I am almost there.
Thanks
-
Re: VB - Spell Check a Textbox
Welcome to VB Forums!
You might want to check this out.
-
Re: VB - Spell Check a Textbox
Thanks for the link. I copied the code and put it in a new module. I couldn't get it to even compile. It doesn't like
Public moApp As Word.Application
or
Set oDoc = moApp.Documents.Add(, , 1, True)
I don't know if there are other problems.
-
Re: VB - Spell Check a Textbox
You have to set a reference to WORD in the project first.
Quote:
Microsoft Word x.0 Object Library
Use whatever version that you have. I have Office XP, which is 10.0
-
Re: VB - Spell Check a Textbox
I made the reference and there was other code that caused problems such as clipboard.clear
Thanks for your help. I'll work with the other code and see if I can stop F7 from running the normal Spell Check after the spell check in the code.
-
Re: VB - Spell Check a Textbox
Martin,
Here is my code. I don't know if you'll be able to get it to run...it has an Oracle database under it. I hope you (or someone else) can help.
-
Re: VB - Spell Check a Textbox
Sorry, but I couldn't even come close to running it since I don't have a dll and a bunch of ocx's it's looking for. If you can tell me which form(s) have the spell checking I'll try to see if I can find anything wrong. Another way we could go about it would be if you could create a plain-vanilla app that has the problem.
-
Re: VB - Spell Check a Textbox
Sorry for the long delay on posting a message back. The form that contains the problem is frmReview (the Description field is where I'm testing). The spell checker code is in modSpelling.
I tried to make a plain-vanilla app that had the same problem and guess what...I can't. A similiar program with the same general idea will run spell check without a problem.
-
Re: VB - Spell Check a Textbox
Try adding the highlighted code and perhaps some additional error handling if and when to get the new message.
VB Code:
Public Sub CheckSpelling(t As Control) '(t As TextBox)
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
'Create a new instance of word Application
If Len(t.Text) > 0 Then
App.OleRequestPendingTimeout = 999999
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Select Case objWord.Version
Case "9.0", "10.0", "11.0" 'Office 2000, xp, 2k3
Set objDoc = objWord.Documents.Add(, , 1, True)
Case Else 'Office 97
Set objDoc = objWord.Documents.Add
End Select
objDoc.Content = t.Text
objDoc.CheckSpelling
[HL="#FFFF80"]Dim myErr As Long
myErr = objWord.ActiveDocument.SpellingErrors.Count
'User pressed Cancel button
'(Pressing Ignore reduces the count, pressing Cancel doesn't)
If myErr > 0 Then
MsgBox "Cancelled"
End If[/HL]
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 spelling 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
End If
Done:
Exit Sub
'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
Resume Done
End Sub
-
Re: VB - Spell Check a Textbox
I added the highlighted code. I changed it to show the number of ...SpellingErrors.Count in a message box b/c the ignore word didn't fire the message.
It still errors out, before it runs that highlighted code.
-
Re: VB - Spell Check a Textbox
I'm sorry you are having a problem but I can't help any futher unless I have a project that I can run that shows the problem.
-
Re: VB - Spell Check a Textbox
I'm a genius!!!!
I figured out the problem I was encountering. I moved the clean up of the object to before the message box informing the user that the check was complete. This seems to have corrected the problem of the Run-time error. I guess it was loosing reference to the word document object.
GO ME!
-
Re: VB - Spell Check a Textbox
I am able to accomplish this, but can anybody tell me how to apply this to a Rich Text Box without loosing the Rich Text Formattin.
-
Re: VB - Spell Check a Textbox
I write a newsletter using vb. The spell check code you have provided is outstanding. I am encounting a problem though. I often have html code (for tables) embedded in my text. When I use this spell check code, it finds a lot of duplicate or repeating 'words' that are just repeating html code. One set in particular is picked up a lot: "0px 0px 0px 0px". The winword code assumes the 0px is repeated and an error. It asks me to "Ignore" or "Delete". There can be 100's of these in my code. Is there any way to tell winword or code that these repeating 'words' are not to be checked?
Thanks in advance!
-
Re: VB - Spell Check a Textbox
Quote:
Originally Posted by turnertrends
I write a newsletter using vb. The spell check code you have provided is outstanding. I am encounting a problem though. I often have html code (for tables) embedded in my text. When I use this spell check code, it finds a lot of duplicate or repeating 'words' that are just repeating html code. One set in particular is picked up a lot: "0px 0px 0px 0px". The winword code assumes the 0px is repeated and an error. It asks me to "Ignore" or "Delete". There can be 100's of these in my code. Is there any way to tell winword or code that these repeating 'words' are not to be checked?
Thanks in advance!
http://www.vbforums.com/attachment.p...id=47243&stc=1I don't currently have time to look into that but the code is there for you to do what you want with, so you can give it a try if you want to.
-
Re: VB - Spell Check a Textbox
Quote:
Originally Posted by turnertrends
I write a newsletter using vb. The spell check code you have provided is outstanding. I am encounting a problem though. I often have html code (for tables) embedded in my text. When I use this spell check code, it finds a lot of duplicate or repeating 'words' that are just repeating html code. One set in particular is picked up a lot: "0px 0px 0px 0px". The winword code assumes the 0px is repeated and an error. It asks me to "Ignore" or "Delete". There can be 100's of these in my code. Is there any way to tell winword or code that these repeating 'words' are not to be checked?
Thanks in advance!
You can add the html code that is giving you issues to a custom dictionary or just add it to the default dictionary.
-
Re: VB - Spell Check a Textbox
Hi there,
May I know what is the different between objWord.Documents.Add(, , 1, True) and Set objDoc = objWord.Documents.Add for different version of objWord.Documents?
Thanks
Dick
-
Re: VB - Spell Check a Textbox
Word 97 did not support the arguments as 200 and newer does.
-
Re: VB - Spell Check a Textbox
May I know what are the argurments stand for (,,1,true) and what will happen if i omit those argurments in words 2k and above?
thanks in advance
Dick