I just tried to reproduce your problem and I couldn't. If you attach your project I'll take a look at it.
Printable View
I just tried to reproduce your problem and I couldn't. If you attach your project I'll take a look at it.
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
Welcome to VB Forums!
You might want to check this out.
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.
You have to set a reference to WORD in the project first.
Use whatever version that you have. I have Office XP, which is 10.0Quote:
Microsoft Word x.0 Object Library
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.
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.
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.
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.
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
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.
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.
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!
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.
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.Quote:
Originally Posted by turnertrends
You can add the html code that is giving you issues to a custom dictionary or just add it to the default dictionary.Quote:
Originally Posted by turnertrends
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
Word 97 did not support the arguments as 200 and newer does.
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
Its all optional arguments but these are what they are in 200+
.Documents.Add([Template], [NewTemplate], [DocumentType], [Visible])
You can specify a template to base the document creation upon, specify this is to be a new template, doc type has several types it could be, and if to show the document or make it hidden.
All these arguments can be seen in the Object Browser of Word and help file too for more info then what I posted. :).
Hello,
I'm new here and have just found your spell check VB code.
It works a treat as a function embedded in a Module/Form BUT the Word spell check box/form is hidden.
The only way I can get to see it is if I clear the desktop and then click on my program's task bar button.
Do you know a way of forcing the spell check form to the front and visible?
(I am running Vista :mad: and have noticed that your example in #44 still hides the spell check form as above. Not sure if this is relevant)
Thanks
http://www.vbforums.com/attachment.p...id=47243&stc=1
Sorry, but since I assume that your problem is Vista related and I don't have Vista, I can't do anything about it. You might want to try the spell checker in RobDog888's signature.
Thanks for the quick reply Mr Martin.
I have seen Mr Dog888's code but it is too bespoke/specialized for my application. I need a more integrated function like yours.
I have seen this at the MS site
http://support.microsoft.com/kb/243844/en-us
which doesn't hide the Spell checker quite as well in Vista :)
It is visible in the taskbar however and so it just needs one to click it to reveal it. Not too bad a problem.
I will use your error checking etc to check for the presence of Word and also produce a msgbox to tell the user when the spell check is complete.
Thank you for your help Mr Martin. I have rated you :thumb:
It is very good program.
Is it possible that it do spell checking for editbox loated in external applications .There is an application that has richedit box with following class information. Could you tell me how to make your program work with it? For example after typing on that application i want to hit F11 and it does spell check for me.
Furthermore, i have word xp is it possible to do spell checking as i type by getting red line under words that are not correct?
Looking forward for your reply.Thanks
RichEdit20A
#32770
AtlAxWin71
ATL:006ED050
WTL_SplitterWindow
WTL_SplitterWindow
WTL_SplitterWindow
WTL_SplitterWindow
DlgGroupChat Window Class
window that holds that edit box class infor:
DlgGroupChat Window Class
I'm sorry but I can't help you with that.
I'd love to use this code to add the spell check function to my app. I have users ranging from word 2K to 2K7, so does anyone know if there is a modification that is needed to include word version beyond 2k3? Also, I will be running the code from forms in access 2k7 runtime only. Doing a direct reference to spellcheck causes an error on any machines without office 2k7, so this code seems like the right trick?
Great code guys thanks alot.
Is this thread still being looked at ? I have a problem with the following...
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
There is no 'left' in vb.net I tried substring, but objDoc.Content (or.ToString) does not give the corrected text.
The code as supplied is VB6 and not .Net.
...the rest works OK in .net. What changes to I have to make for .net, or is there a totaly different approach ?
I am new to this forum and this is my first post. Not sure if this thread is still active but am seeking advice as a newbie!
I have applied Martin's code (its excellent!) to my application (VB6, Office 2003 under XP). It all works fine apart from one annoying behaviour I cannot figure. When the Word spell checker form is displayed, it does not always appear at the front of the screen. But this behaviour is inconsistent - sometimes it does, and sometimes not and I have been unable to identify why this variation is occurring.
Is there a foolproof method of forcing the spell checker form to the front of the display area when the spell checking is invoked?
As far as I remember nobody else has reported this issue, but I'll see if I can reproduce it. In any case you might want to try RobDog's similar code here.
Martin,
Thanks for the prompt response - I may be being dense (sorry!) but the link for Robdog's code doesn't appear to take me anywhere! Can you advise where I can see his code to try it? :o
Thanks
Try clicking the VB/Office Guru™ Word SpellChecker™ VB6 link in his signature (see post #81).
Anyone Know How To Do This In C#?
I have a VB.NET version in my signature and you can use one of those converters to convert it to C#
can it be done for Office 2007??????////////
sorry fr reviving this old post!!!!!!
thanx in advance
wiz....
Did you read the last half-dozen or so posts?
i have been and cudn't find any thing related to Office 2007!!!!
You only need to use Late Binding in order to support multiple compatible versions. See my FAQ on Late Binding - http://www.vbforums.com/showthread.php?t=406640 for more and code examples.