-
Re: Advanced VB/Office Guru™ SpellChecker™
The Word Object Model doesnt expose that exact wavy underlinning but it does have a close similar match.
Specify the wdUnderlineWavy and .UnderlineColor to best duplicate the spellchecking spelling error identifier. Its very close.
This is in Word 2007 so I cant say its in the previous versions.
Code:
Selection.Font.Underline = wdUnderlineWavy
Selection.Font.UnderlineColor = wdColorRed
-
Re: Advanced VB/Office Guru™ SpellChecker™
Hi RobDog888,
For some reason when I implement your code in the system accessing localhost database it works fine, however when it is using the server database the spellcheck functionality does not function. I know it is still accessing and opening MS Word (because the temp files in MS Word keep increasing invisibly, when you open a new MS Word you realize the instance has incremented), but I am not sure how to fix this...or why this should happen.
-
Re: Advanced VB/Office Guru™ SpellChecker™
I am using the code in an access 2000 database. I have a richtextbox using it as a mini-word application. When I run the code it says the spelling is complete (no spelling errors) but it's clear that I do have them. I will just type in a bunch of letters and it passes.
I noticed then in word it would do the same thing, I had to delete the custom.dic file to get word correctly working again with the default dictionary. However the problem still presists in my application.
Has anyone got this working in an access or richtextbox environment?
-
Re: Advanced VB/Office Guru™ SpellChecker™
For RichTextBoxes I found another piece of code that works much better. Create a button and put this in the code. RTFText is the name of your RichTextBox. I'm using this in Access 2000 and it is working great.
Code:
On Error GoTo SpellCheckErr
Dim oWord As Object
Set oWord = CreateObject("Word.Application")
'Save the RTF Box contents to a temporary file
rtfText.SaveFile "C:\TEST.RTF", rtfRTF
'Open the saved document and spellcheck it
oWord.Documents.Open ("C:\TEST.RTF")
oWord.ActiveDocument.SpellingChecked = False
oWord.Options.IgnoreUppercase = False
oWord.ActiveDocument.CheckSpelling
'Save the changes to the RTF file & close
oWord.ActiveDocument.Save
oWord.ActiveDocument.Close
oWord.Quit
'Load the changes back to the rtf text box.
rtfText.LoadFile "C:\TEST.RTF", rtfRTF
Set oWord = Nothing
Screen.MousePointer = vbDefault
MsgBox "Spell Check is complete", _
vbInformation, "Spell Check"
Exit Sub
SpellCheckErr:
MsgBox Err.Description, vbCritical, _
"Spell Check"
Set oWord = Nothing
-
Re: Advanced VB/Office Guru™ SpellChecker™
You may run into issues with different OS' and permissions to write a file to a particular directory.
For ex. in Vista writting to the root drive is locked down and prohibited. This wopuld mean writting to some other location and dont think that yoiu could use the Program Files directory as that is locked down too. )
-
Re: Advanced VB/Office Guru™ SpellChecker™
In your code for spelling and grammer checking, is there a way to hide the Check Grammer checkbox on the Spelling and Grammer dialog? I want to force the user to have both spelling and grammer checked without providing the option to disable the grammer checking. Also, is there a way to disable the Options button on the Spelling and Grammer dialog?
-
Re: Advanced VB/Office Guru™ SpellChecker™
Finally, which code I can use in my VB6 program for spell-check? Please help me out.
Thanks.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by VBLearner6
Finally, which code I can use in my VB6 program for spell-check? Please help me out.
Thanks.
Whats your question/issue?
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by bikertz
In your code for spelling and grammer checking, is there a way to hide the Check Grammer checkbox on the Spelling and Grammer dialog? I want to force the user to have both spelling and grammer checked without providing the option to disable the grammer checking. Also, is there a way to disable the Options button on the Spelling and Grammer dialog?
To modify any control on Words spell checker dialog (other then prepopulating it) you would need to use a C++ dll to subclass Word and modify the dialog via APIs. A bit of work but can be done.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Hi guys, thank you for this great thread. I am using Visual Basic 2005.
I have code similar to this and the spell checker is working.
The problem I am having is if the user brings up the spell checker dialog window and then switches to another application and then alt-tabs back to my application, things freeze up.
The user can alt-tab back to the Word dialog box and close it, but if he tries to go directly to the application it freezes.
Does the line: "App.OleRequestPendingTimeout = 999999" prevent this freezing, and if not is there another way to fix this?
Thanks again :)
-
Re: Advanced VB/Office Guru™ SpellChecker™
Didn't realize above message saved, srry for the double post
-
Re: Advanced VB/Office Guru™ SpellChecker™
No prob and Thanks :)
Since you are using .NET you should be using something similar to my VB.NET version:
http://www.vbforums.com/showthread.php?t=359879
In .NET perhaps creating a separate thread to process the spellchecking may solve the siiue ;)
I'm working on a new updated version and shold be ready soon :)
-
Re: Advanced VB/Office Guru™ SpellChecker™
I tried the code and am still having the freezing issue when the user tabs out to another app and then back to my app while the spellchecker is still running, so I put in a workaround where I will show Word in the task bar below and they can click on that to get back to the spellchecker and avoid freezing.
Thanks again for your help :)
-
Re: Advanced VB/Office Guru™ SpellChecker™
No prob.
What version of Word are you using so we can track any issues with a particular version?
-
Re: Advanced VB/Office Guru™ SpellChecker™
Word 2003 (Word 11.5604.8202)
-
Re: Advanced VB/Office Guru™ SpellChecker™
Hello,
I tried this code and got this error.
Code:
Error: User defined type not defined.
Public moApp As Word.Application
I copied and pasted your code to a module then
I cut the bottom part and pasted it into a form.
Where did I go wrong?
-
Re: Advanced VB/Office Guru™ SpellChecker™
Rather than just copy+paste code from somewhere, you should at least read the comments at the top of it:
Quote:
Code:
'Early binding:
'Add a reference to MS Word xx.0 Object Library
'Modifications: none.
'Late binding:
'No references needed to any version of Word
'Modifications: Change object vars definitions (moApp & oDoc) to Object
'Change constants to their numeric equilivalents.
-
Re: Advanced VB/Office Guru™ SpellChecker™
You are better off using Late Binding as I remember reading your Word Processor thread.
-
Re: Advanced VB/Office Guru™ SpellChecker™
I did read the notes and still didn't know what it meant.
If I had examples of binding or whatever, it would help. I
could then figure out what does what.
-
Re: Advanced VB/Office Guru™ SpellChecker™
-
Re: Advanced VB/Office Guru™ SpellChecker™
A little too complicated for me. I think I'll just
stick with trying to figure out how to disable the
visualizations in Window Media Player control,
using a button. Is there a code for that?
I'd like to give the user an option to use it or not.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Its not hard. If you look at teh two coding examples of Early vs Late you can see the only differences are ...
Early:
Add a reference to Word (or whatever you are automating)
Late:
No reference needed
Declare variables as Object
Declare Constants yourself as no reference means they wont be declared
For the WMP question, have you tried a search yet?
Ps, dont give up so soon. ;)
-
Re: Advanced VB/Office Guru™ SpellChecker™
Thanks for the encouragement.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Post up any more questions or issues you come across and we all would be happy to help.
-
Re: Advanced VB/Office Guru™ SpellChecker™
-
Re: Advanced VB/Office Guru™ SpellChecker™
-
Re: Advanced VB/Office Guru™ SpellChecker™
Moring All, first time here - exciting!
I'm trying to get this goint in Access for 2 reasons: 1. it looks awsome and I like it therfore I want to (already got the built in one working fine but you know :)) 2. Acess 2007 runtime doesn't have a spell check and I need to add one.
I've imported the code and popped it into a new module. I've already got a reference to word 11 so I'm guessing I'm in with early binding (in 2003 at the mo, work out 2007 later).
Just running debug and had to change the mouse pointer to 11 which makes me think I should be using late binding?? Anyway, whilst debuggin, it stops at App.OleRequestPendingTimeout = 999999 with a variable not defined - I'm guessing I need to either add a reference or make a change in accordance with late binding? Not sure how though, any help would be greatly appreciated.
Martyn
-
Re: Advanced VB/Office Guru™ SpellChecker™
I have been using this code quite successfully for some time but have now hit a problem. The scenario is a VB6.0 application using Office 2010 spell check. Sometimes it works and sometimes the users get a message stating that Spell check is currently unavailable. Below is the code from my app:
Code:
Public Function SpellMe(ByVal msSpell As String) As String
On Error GoTo No_Bugs
Dim oDoc As Word.Document
Dim iWSE As Integer
Dim iWGE As Integer
Dim sReplace As String
Dim lresp As Long
If msSpell = vbNullString Then Exit Function
InitializeMe
If gDiags Then
frmDiags.AddLine moApp.Version
End If
Select Case moApp.Version
Case "9.0", "10.0", "11.0", "12.0", "14.0"
Set oDoc = moApp.Documents.Add(, , 1, True)
Case "8.0"
Set oDoc = moApp.Documents.Add
Case Else
MsgBox "Unsupported Version of Word.", vbOKOnly + vbExclamation, "VB/Office Guru™ SpellChecker™"
Exit Function
End Select
Screen.MousePointer = vbHourglass
App.OleRequestPendingTimeout = 999999
oDoc.Words.First.InsertBefore msSpell
iWSE = oDoc.SpellingErrors.count
iWGE = oDoc.GrammaticalErrors.count
'<CHECK SPELLING AND GRAMMER DIALOG BOX>
If iWSE > 0 Or iWGE > 0 Then
'<HIDE MAIN WORD WINDOW>
moApp.Visible = False
If (moApp.WindowState = wdWindowStateNormal) Or (moApp.WindowState = wdWindowStateMaximize) Then
moApp.WindowState = wdWindowStateMinimize
Else
moApp.WindowState = wdWindowStateMinimize
End If
'</HIDE MAIN WORD WINDOW>
'<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.CheckGrammarWithSpelling = True
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.SuggestSpellingCorrections = True
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.IgnoreUppercase = True
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.IgnoreInternetAndFileAddresses = True
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.IgnoreMixedDigits = False
moApp.Dialogs(wdDialogToolsSpellingAndGrammar).Application.options.ShowReadabilityStatistics = False
'</PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
'<DO ACTUAL SPELL CHECKING>
moApp.Visible = True
moApp.Activate
lresp = moApp.Dialogs(wdDialogToolsSpellingAndGrammar).display
'</DO ACTUAL SPELL CHECKING>
If lresp < 0 Then
moApp.Visible = True
MsgBox "Corrections Being Updated!", vbOKOnly + vbInformation, App.ProductName
Clipboard.Clear
oDoc.Select
oDoc.Range.copy
sReplace = Clipboard.GetText(1)
'<FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
If (InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1) Then
sReplace = Mid$(sReplace, 1, Len(sReplace) - 2)
End If
'</FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
SpellMe = sReplace
ElseIf lresp = 0 Then
MsgBox "Spelling Corrections Have Been Canceled!", vbOKOnly + vbCritical, "VB/Office Guru™ SpellChecker"
SpellMe = msSpell
End If
Else
MsgBox "No Spelling Errors Found" & vbNewLine & "Or No Suggestions Available!", vbOKOnly + vbInformation, _
"VB/Office Guru™ SpellChecker"
SpellMe = msSpell
End If
'</CHECK SPELLING AND GRAMMER DIALOG BOX>
oDoc.Close False
Set oDoc = Nothing
'<HIDE WORD IF THERE ARE NO OTHER INSTANCES>
If KillMe = True Then
moApp.Visible = False
End If
'</HIDE WORD IF THERE ARE NO OTHER INSTANCES>
Screen.MousePointer = vbNormal
Exit Function
No_Bugs:
If err.Number = "91" Then
Resume Next
ElseIf err.Number = "462" Then
MsgBox "Spell Checking Is Temporary Un-Available!" & vbNewLine & "Try Again After Program Re-Start.", _
vbOKOnly + vbInformation, "ActiveX Server Not Responding"
Screen.MousePointer = vbNormal
ElseIf err.Number = 429 Then
Set moApp = Nothing
Resume Next
Else
MsgBox err.Number & " " & err.Description, vbOKOnly + vbInformation, App.ProductName
Screen.MousePointer = vbNormal
End If
End Function
Any help would be greatly appreciated.
Thanks.
-
Re: Advanced VB/Office Guru™ SpellChecker™
I dont have 2010 installed on my work computer but have you tried stepping through the code to see where the hangup lies?
-
Re: Advanced VB/Office Guru™ SpellChecker™
It fails at Set oDoc = moApp.Documents.Add(, , 1, True) in that at the next step it says "the action cannot be performed as no document is open" or "Spell Check is currently unavailable". As far as Word 2010 goes it isn't just affecting this Spell Check code but everywhere I need to automate Word.
Thanks
-
Re: Advanced VB/Office Guru™ SpellChecker™
Rob,
I reworked your code into a "drop in" class module that does it's own initializing and termination, negating the user doing so in their form code. I also added some extra properties and events. Your copyright suggests I should ask permission before posting it here. Would it be okay to do so?
Thanks!
- Kev
-
Re: Advanced VB/Office Guru™ SpellChecker™
Hopefully this thread is still being followed? Maybe? :)
I discovered something in your sample that doesn't make sense, and damned if I can find the answer in MSFT's docs.
If you change the CheckGrammarWithSpelling option to false, and click Cancel on the Dialog, lResp returns -1 (versus 0 for Cancel/Close). Switching it back to True restores normal behaviour.
So, any idea why that might be?
I'm tossing around checking the spelling errors count for something > 0 as clicking Cancel does not lower the error count like Ignore does.
-
Re: Advanced VB/Office Guru™ SpellChecker™
If memory servers me right, the calcel/close values are not self explainatory. There is also a third value -2 which means something too.
I will dig up my old files and see what somments I have from r n d.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Rob -
The MSDN says the following (http://msdn.microsoft.com/en-us/libr...g.display.aspx)
-2 = The Close button.
-1 = The OK button.
0 (zero) = The Cancel button.
> 0 (zero) = A command button: 1 is the first button, 2 is the second button, and so on.
My observation is, based on the Grammar check set to false is the return value is always -1, regardless what button is clicked. Odd behaviour to say the least (but with MSFT, this is typically the norm, especially when ti comes to automating various office classes). As I noted before, I was able to compensate for this by checking for unchecked errors after the user cancels out. Couldn't figure out why the return value is so flaky, so...
I'd still like to get your permission to post my class based on your code. I think you'd find the enhancements nod worthy. ;-)
-
Re: Advanced VB/Office Guru™ SpellChecker™
Today i have also come up with the same problem. Everything works fine but when you try to use Word 2010, it gives the following error. However my error description is slightly different
4605 The Add method or property is not available because the document is a rich text edit control.
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by
abbid_siddiqui
Today i have also come up with the same problem. Everything works fine but when you try to use Word 2010, it gives the following error. However my error description is slightly different
4605 The Add method or property is not available because the document is a rich text edit control.
I've found out the reason for this problem but don't have any idea how to resolve this? The error occurs when there is an unclosed instance of Spell Checker in the Task Manager (don't know why it remains in task manager). If you close that and re-run the application, it works.
Rob, could you please let me know how to avoid this error?
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by
RobDog888
I wrote this to demonstrate how to take full advantage of MS Word's built in Spelling and Grammer checker
Oh, the irony...
-
Re: Advanced VB/Office Guru™ SpellChecker™
I know this is an old thread but we recently starting having issues where the word that is misspelled is no longer being displayed in the 'Not in Dictionary' portion of the spell checker. I have created a new project from RobDog888 example in this thread and that is doing the same thing. Anyone else experiencing this and/or have suggestions on how to get it to display the misspelled word again? I suspect it is a MS change/update to office.
Here is an example. Thanks!
Attachment 187199
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by
ColinE66
Oh, the irony...
Lol!
-
Re: Advanced VB/Office Guru™ SpellChecker™
Quote:
Originally Posted by
ColinE66
Oh, the irony...
Yup! Testing you guys to see if anyone notices. :D
-
Re: Advanced VB/Office Guru™ SpellChecker™