-
May 23rd, 2003, 11:30 AM
#1
VB - Spell Check a Textbox
Add this code to a command button or popup menu item.
VB Code:
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
'Create a new instance of word Application
Set objWord = CreateObject("word.Application")
Select Case objWord.Version
'Office 2000
Case "9.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office XP
Case "10.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else ' Office 97
Set objDoc = objWord.Documents.Add
End Select
objDoc.Content = Text1.Text
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
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
'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
Text1.Text = strResult
Exit Sub
-
Jun 11th, 2003, 11:41 AM
#2
Stuck in the 80s
I'm guessing Word has to be installed for this to work?
-
Jun 11th, 2003, 12:04 PM
#3
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 11th, 2003, 02:00 PM
#4
-
Sep 26th, 2003, 11:48 AM
#5
Lively Member
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
How does this translate into VB.net? Any ideas? It's the one line that's not compatible in our app. The Left function is considered an integer...If you could just let me know what this does (dump contents of Word doc into strResult?), I can probably figure out how to tweak it.
Thanks,
mike
-
Sep 26th, 2003, 02:56 PM
#6
VB Code:
strResult = objDoc.Content.Substring(0,objDoc.Content.Length-1)
Probably something like that.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Sep 29th, 2003, 09:07 AM
#7
New Member
wow helpful
So wut your saying here, is that if I have a text game I can spell check the commands entered by the user? accordingly to the command?
"I grow tired of you inscrupulant drivel, foolish mortal."-Tormentlord
tormentlord@yahoo.com
achilles_ian@hotmail.com
www.darkism.8m.com
-
Sep 29th, 2003, 10:02 AM
#8
If you have Word on your PC and you add the code to a textbox in your game, the textbox will will behave the same way that Word does when you press F7.
-
Oct 14th, 2003, 12:24 AM
#9
New Member
component request pending
hi
when spell check window is open and if you try to switch focus to some other windows application, a msg box appears with message "This action cannot be completed because other application is busy. Choose 'Switch To' to activate the busy application and correct the problem."
how to get rid of this message window and display the spell check window as modal window?
thanks in advance.
-
Oct 14th, 2003, 11:05 AM
#10
Add the following before the word object is created.
App.OleRequestPendingTimeout = 999999
-
Dec 17th, 2003, 08:43 PM
#11
-
Dec 17th, 2003, 09:11 PM
#12
If Wordperfect has an object module that exposes the right properties then I guess so, but I've no experience with it.
-
Dec 19th, 2003, 04:17 PM
#13
Supreme User
-
Jan 17th, 2005, 01:17 PM
#14
Addicted Member
Re: VB - Spell Check a Textbox
Originally Posted by Madboy
Whats WordPerfect?
God damn, I feel old... And I'm only 24.
QUESTION: What would happen if Word isnt installed? Nothing? or would the system generate an error?
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
Jan 24th, 2005, 06:09 PM
#15
Hyperactive Member
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!
Brenda
If it weren't for you guys, where would I be?
-
Jan 24th, 2005, 07:17 PM
#16
Re: VB - Spell Check a Textbox
Have you included the Reference to Word?
-
Jan 25th, 2005, 12:39 PM
#17
Hyperactive Member
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.??????
Brenda
If it weren't for you guys, where would I be?
-
Feb 15th, 2005, 08:18 PM
#18
New Member
Re: VB - Spell Check a Textbox
Hi!
Does anyone have any idea how to make the spell and grammar check multilanguage?
Thanks!
-
Feb 15th, 2005, 08:21 PM
#19
Re: VB - Spell Check a Textbox
Does Word do it? If so then it should be fairly easy. If not then....?
-
Feb 15th, 2005, 08:22 PM
#20
New Member
Re: VB - Spell Check a Textbox
-
Feb 15th, 2005, 08:29 PM
#21
New Member
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
-
Apr 5th, 2008, 11:54 PM
#22
Hyperactive Member
Re: VB - Spell Check a Textbox
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.
-
Apr 6th, 2008, 12:08 AM
#23
Re: VB - Spell Check a Textbox
The code as supplied is VB6 and not .Net.
-
Apr 6th, 2008, 12:38 AM
#24
Hyperactive Member
Re: VB - Spell Check a Textbox
...the rest works OK in .net. What changes to I have to make for .net, or is there a totaly different approach ?
-
Dec 19th, 2003, 04:37 PM
#25
-
Dec 19th, 2003, 04:40 PM
#26
Supreme User
Sounds good, does anybody use it?
-
Dec 19th, 2003, 04:58 PM
#27
You really are young. WordPerfect was the word-processing program before MS Word came along. I'm sure many, many people still use it, but no doubt less than Word.
-
Dec 19th, 2003, 05:03 PM
#28
Supreme User
hehehe, i didnt realise. Im only 17 so there you go, didnt realise such a thing existed.
Well, you learn something new everyday
-
Jan 4th, 2004, 08:45 PM
#29
Member
Martin I am trying to use the above code with numerous textboxes on the same form and have altered it to achieve this. The problem I am having is if I cancel the spellchecker it proceeds to the next textbox and opens again. Is there any way I can capture the return value of the spellchecker so if it is canceled I can exit the sub
-
Jan 4th, 2004, 10:45 PM
#30
Please post your code; at least the cmdSpell_Click() sub.
-
Jan 5th, 2004, 04:28 PM
#31
Member
Basically a company using access 97 runtime with office 2003 want to see if they can use the 2003 spell checker as the 97 office spellchecker is no longer installed. So I want to use this code in an access form.
I was hoping to loop through all the controls on the form but first altered your code slightly to see how it would handle two text boxes.
VB Code:
Private Sub Command0_Click()
Dim objWord As Object
Dim objDoc1, ojbDoc2 As Object
Dim strResult1, strResult2 As String
'Create a new instance of word Application
Set objWord = CreateObject("word.Application")
Select Case objWord.Version
'Office 2000
Case "9.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office XP
Case "10.0", "11.0"
Set objDoc1 = objWord.Documents.Add(, , 1, True)
Set objDoc2 = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else ' Office 97
Set objDoc = objWord.Documents.Add
End Select
Me.Text1.SetFocus
objDoc1.Content = Text1.Text
objDoc1.CheckSpelling
strResult1 = Left(objDoc1.Content, Len(objDoc1.Content) - 1)
Me.Text2.SetFocus
objDoc2.Content = Text2.Text
objDoc2.CheckSpelling
strResult2 = Left(objDoc2.Content, Len(objDoc2.Content) - 1)
If Text2.Text = strResult2 Then
Text1.SetFocus
If Text1.Text = strResult1 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
End If
'Clean up
objDoc1.Close False
objDoc2.Close False
Set objDoc1 = Nothing
Set objDoc2 = 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
Text1.SetFocus
Text1.Text = strResult1
Text2.SetFocus
Text2.Text = strResult2
Exit Sub
End Sub
How would you approach this?
-
Jan 5th, 2004, 05:51 PM
#32
VB Code:
Private Sub Command0_Click()
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
Dim ctl As Control
App.OleRequestPendingTimeout = 999999
'Create a new instance of word Application
Set objWord = CreateObject("word.Application")
Select Case objWord.Version
'Office 2000
Case "9.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office XP
Case "10.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else ' Office 97
Set objDoc = objWord.Documents.Add
End Select
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
objDoc.Content = ctl.Text
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
If ctl.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spelling checking for " & ctl.Name & " is complete.", vbInformation + vbOKOnly
End If
End If
Next
'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
Text1.Text = strResult
End Sub
BTW it's a common mistake but when things are defined the way
you did it in Dim objDoc1, ojbDoc2 As Object only objDoc2 is an Object, objDoc1 is left as a Variant.
-
Jan 5th, 2004, 06:59 PM
#33
Member
Cheers for the tip
App.OleRequestPendingTimeout = 999999
is not recognised in Access is this line necessary. I tried commenting it out and alter the code as such for access but still the word doc comes up if I cancel the spellchecker during the check.
VB Code:
Private Sub Command0_Click()
Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
Dim ctl As Control
'Create a new instance of word Application
Set objWord = CreateObject("word.Application")
Select Case objWord.Version
'Office 2000
Case "9.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office XP
Case "10.0", "11.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else ' Office 97
Set objDoc = objWord.Documents.Add
End Select
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.SetFocus
objDoc.Content = ctl.Text
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
If ctl.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spelling checking for " & ctl.Name & " is complete.", vbInformation + vbOKOnly
End If
End If
Next
'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
Text1.SetFocus
Text1.Text = strResult
End Sub
Is this because I have ommitted 'App.OleRequestPendingTimeout = 999999' ?
-
Jan 5th, 2004, 09:05 PM
#34
The App.OleRequestPendingTimeout = 999999 came from the problem that sv_bhaskar pointed out above and you may not need it.
Try objWord.Visible = False for your problem.
-
Jan 5th, 2004, 10:47 PM
#35
Member
No that didn't work either. I guess I will just force them to check only one text box at a time.
Cheers for your help.
-
Jan 6th, 2004, 12:33 PM
#36
I may not be able to do anything about it but would you like to send me your project?
-
Jan 6th, 2004, 03:21 PM
#37
Member
I haven't added it to my project yet as I was just investigating the possibility. I just created a form in Access with a couple of textboxes and put your code under a command button. Unfortunately problems arose when cancelling the spellchecker.
-
Jan 6th, 2004, 03:24 PM
#38
How about attaching that project or creating a new one that demonstrates the problem.
-
Jan 15th, 2004, 11:44 AM
#39
Three problems have been reported by rike when using my code in VBA. Those problems are:
1. Text boxes that contain carriage returns are displayed as non recognisable character formats after spell checking
2.When the spell checker window is moved, the screen is not repainted
3 When users try to use other applications while the spellchecker is in progress the screen gets confused and appears to crash.
I don't program in VBA but I have been able to verify that problem 1 occurs in VB as well. The following is a fix for that problem. (Add the bolded line to the existing code).
VB Code:
objDoc.CheckSpelling
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
' Correct the carriage returns
[b]strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))[/b]
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
-
May 9th, 2005, 05:53 PM
#40
Lively Member
Re: VB - Spell Check a Textbox
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|