Page 1 of 3 123 LastLast
Results 1 to 40 of 101

Thread: VB - Spell Check a Textbox

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    VB - Spell Check a Textbox

    Add this code to a command button or popup menu item.

    VB Code:
    1. Dim objWord As Object
    2.     Dim objDoc  As Object
    3.     Dim strResult As String
    4.    
    5.     'Create a new instance of word Application
    6.     Set objWord = CreateObject("word.Application")
    7.  
    8.     Select Case objWord.Version
    9.         'Office 2000
    10.         Case "9.0"
    11.             Set objDoc = objWord.Documents.Add(, , 1, True)
    12.         'Office XP
    13.         Case "10.0"
    14.             Set objDoc = objWord.Documents.Add(, , 1, True)
    15.         'Office 97
    16.         Case Else ' Office 97
    17.             Set objDoc = objWord.Documents.Add
    18.     End Select
    19.  
    20.     objDoc.Content = Text1.Text
    21.     objDoc.CheckSpelling
    22.  
    23.     strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    24.  
    25.     If Text1.Text = strResult Then
    26.         ' There were no spelling errors, so give the user a
    27.         ' visual signal that something happened
    28.         MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    29.     End If
    30.    
    31.     'Clean up
    32.     objDoc.Close False
    33.     Set objDoc = Nothing
    34.     objWord.Application.Quit True
    35.     Set objWord = Nothing
    36.  
    37.     ' Replace the selected text with the corrected text. It's important that
    38.     ' this be done after the "Clean Up" because otherwise there are problems
    39.     ' with the screen not repainting
    40.     Text1.Text = strResult
    41.  
    42.     Exit Sub

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm guessing Word has to be installed for this to work?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Yup
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Bugger
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Lively Member
    Join Date
    Jun 2001
    Posts
    107
    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

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. 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

  7. #7
    New Member Tormentlord's Avatar
    Join Date
    Sep 2003
    Location
    Charon
    Posts
    4

    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

  8. #8

  9. #9
    New Member
    Join Date
    Sep 2001
    Posts
    9

    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.

  10. #10

  11. #11
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Thumbs up Spell and Grammar Checker

    Marty,
    Today at work we were playing around with your code in order to see if we could spell check and check the grammar of the data contained in the Text box. We changed the following snippet:

    VB Code:
    1. objDoc.CheckSpelling

    to

    VB Code:
    1. objDoc.CheckGrammar

    and viola it worked! But you probably already knew this but I think the other forum members might be able to intergrate this into their projects.

    Do you know a way this code could be modified to work with Wordperfect?
    Last edited by Mark Gambo; Dec 18th, 2003 at 03:31 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  12. #12

  13. #13
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Whats WordPerfect?

  14. #14

  15. #15
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Sounds good, does anybody use it?

  16. #16

  17. #17
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    hehehe, i didnt realise. Im only 17 so there you go, didnt realise such a thing existed.

    Well, you learn something new everyday

  18. #18
    Member
    Join Date
    Nov 2002
    Posts
    53
    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

  19. #19

  20. #20
    Member
    Join Date
    Nov 2002
    Posts
    53
    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:
    1. Private Sub Command0_Click()
    2.     Dim objWord As Object
    3.     Dim objDoc1, ojbDoc2  As Object
    4.     Dim strResult1, strResult2 As String
    5.    
    6.     'Create a new instance of word Application
    7.     Set objWord = CreateObject("word.Application")
    8.  
    9.     Select Case objWord.Version
    10.         'Office 2000
    11.         Case "9.0"
    12.             Set objDoc = objWord.Documents.Add(, , 1, True)
    13.  
    14.         'Office XP
    15.         Case "10.0", "11.0"
    16.             Set objDoc1 = objWord.Documents.Add(, , 1, True)
    17.             Set objDoc2 = objWord.Documents.Add(, , 1, True)
    18.                    
    19.         'Office 97
    20.         Case Else ' Office 97
    21.             Set objDoc = objWord.Documents.Add
    22.     End Select
    23.  
    24.     Me.Text1.SetFocus
    25.     objDoc1.Content = Text1.Text
    26.     objDoc1.CheckSpelling
    27.  
    28.     strResult1 = Left(objDoc1.Content, Len(objDoc1.Content) - 1)
    29.    
    30.    
    31.    
    32.     Me.Text2.SetFocus
    33.     objDoc2.Content = Text2.Text
    34.     objDoc2.CheckSpelling
    35.  
    36.  
    37.     strResult2 = Left(objDoc2.Content, Len(objDoc2.Content) - 1)
    38.  
    39.     If Text2.Text = strResult2 Then
    40.         Text1.SetFocus
    41.         If Text1.Text = strResult1 Then
    42.             ' There were no spelling errors, so give the user a
    43.             ' visual signal that something happened
    44.             MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    45.         End If
    46.     End If
    47.    
    48.     'Clean up
    49.     objDoc1.Close False
    50.     objDoc2.Close False
    51.     Set objDoc1 = Nothing
    52.     Set objDoc2 = Nothing
    53.     objWord.Application.Quit True
    54.     Set objWord = Nothing
    55.  
    56.     ' Replace the selected text with the corrected text. It's important that
    57.     ' this be done after the "Clean Up" because otherwise there are problems
    58.     ' with the screen not repainting
    59.     Text1.SetFocus
    60.     Text1.Text = strResult1
    61.     Text2.SetFocus
    62.     Text2.Text = strResult2
    63.  
    64.     Exit Sub
    65. End Sub

    How would you approach this?

  21. #21

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    VB Code:
    1. Private Sub Command0_Click()
    2.     Dim objWord As Object
    3.     Dim objDoc  As Object
    4.     Dim strResult As String
    5.     Dim ctl As Control
    6.    
    7.     App.OleRequestPendingTimeout = 999999
    8.     'Create a new instance of word Application
    9.     Set objWord = CreateObject("word.Application")
    10.  
    11.     Select Case objWord.Version
    12.         'Office 2000
    13.         Case "9.0"
    14.             Set objDoc = objWord.Documents.Add(, , 1, True)
    15.         'Office XP
    16.         Case "10.0"
    17.             Set objDoc = objWord.Documents.Add(, , 1, True)
    18.         'Office 97
    19.         Case Else ' Office 97
    20.             Set objDoc = objWord.Documents.Add
    21.     End Select
    22.    
    23.     For Each ctl In Controls
    24.         If TypeOf ctl Is TextBox Then
    25.             objDoc.Content = ctl.Text
    26.             objDoc.CheckSpelling
    27.        
    28.             strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    29.        
    30.             If ctl.Text = strResult Then
    31.                 ' There were no spelling errors, so give the user a
    32.                 ' visual signal that something happened
    33.                 MsgBox "The spelling checking for " & ctl.Name & " is complete.", vbInformation + vbOKOnly
    34.             End If
    35.            
    36.         End If
    37.     Next
    38.     'Clean up
    39.     objDoc.Close False
    40.     Set objDoc = Nothing
    41.     objWord.Application.Quit True
    42.     Set objWord = Nothing
    43.  
    44.     ' Replace the selected text with the corrected text. It's important that
    45.     ' this be done after the "Clean Up" because otherwise there are problems
    46.     ' with the screen not repainting
    47.     Text1.Text = strResult
    48.  
    49. 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.

  22. #22
    Member
    Join Date
    Nov 2002
    Posts
    53
    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:
    1. Private Sub Command0_Click()
    2.     Dim objWord As Object
    3.     Dim objDoc  As Object
    4.     Dim strResult As String
    5.     Dim ctl As Control
    6.    
    7.    
    8.     'Create a new instance of word Application
    9.     Set objWord = CreateObject("word.Application")
    10.  
    11.     Select Case objWord.Version
    12.         'Office 2000
    13.         Case "9.0"
    14.             Set objDoc = objWord.Documents.Add(, , 1, True)
    15.         'Office XP
    16.         Case "10.0", "11.0"
    17.             Set objDoc = objWord.Documents.Add(, , 1, True)
    18.         'Office 97
    19.         Case Else ' Office 97
    20.             Set objDoc = objWord.Documents.Add
    21.     End Select
    22.    
    23.     For Each ctl In Controls
    24.         If TypeOf ctl Is TextBox Then
    25.             ctl.SetFocus
    26.             objDoc.Content = ctl.Text
    27.             objDoc.CheckSpelling
    28.        
    29.             strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    30.        
    31.             If ctl.Text = strResult Then
    32.                 ' There were no spelling errors, so give the user a
    33.                 ' visual signal that something happened
    34.                 MsgBox "The spelling checking for " & ctl.Name & " is complete.", vbInformation + vbOKOnly
    35.             End If
    36.            
    37.         End If
    38.     Next
    39.     'Clean up
    40.     objDoc.Close False
    41.     Set objDoc = Nothing
    42.     objWord.Application.Quit True
    43.     Set objWord = Nothing
    44.  
    45.     ' Replace the selected text with the corrected text. It's important that
    46.     ' this be done after the "Clean Up" because otherwise there are problems
    47.     ' with the screen not repainting
    48.     Text1.SetFocus
    49.     Text1.Text = strResult
    50.  
    51. End Sub

    Is this because I have ommitted 'App.OleRequestPendingTimeout = 999999' ?

  23. #23

  24. #24
    Member
    Join Date
    Nov 2002
    Posts
    53
    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.

  25. #25

  26. #26
    Member
    Join Date
    Nov 2002
    Posts
    53
    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.

  27. #27

  28. #28

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    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:
    1. objDoc.CheckSpelling
    2.  
    3.     strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    4.     ' Correct the carriage returns
    5.     [b]strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))[/b]
    6.    
    7.     If Text1.Text = strResult Then
    8.         ' There were no spelling errors, so give the user a
    9.         ' visual signal that something happened
    10.         MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    11.     End If

  29. #29
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by MartinLiss
    VB Code:
    1. objDoc.CheckSpelling
    2.  
    3.     strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    4.     ' Correct the carriage returns
    5.     [b]strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))<b>Three problems have been reported by rike when using my code in VBA. Those problems are:
    6.  
    7. 1. Text boxes that contain carriage returns are displayed as non recognisable character formats after spell checking
    8.  
    9. 2.When the spell checker window is moved, the screen is not repainted
    10.  
    11. 3 When users try to use other applications while the spellchecker is in progress the screen gets confused and appears to crash.
    12.  
    13. 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).
    14.  
    15. </b>
    16.    
    17.     If Text1.Text = strResult Then
    18.         ' There were no spelling errors, so give the user a
    19.         ' visual signal that something happened
    20.         MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    21.     End If
    [/B]
    Martin,

    Nice code.. One question though.. I get a screen flicker and see a word document displayed on my screen for a brief second.. Any ideas as to why?
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  30. #30
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by RudyL
    Martin,

    Nice code.. One question though.. I get a screen flicker and see a word document displayed on my screen for a brief second.. Any ideas as to why?
    objWord.Visible=False

  31. #31
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by jhermiz
    objWord.Visible=False
    That does not work. In fact, if I click on cancel the word document does not close at all.. wierd..
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  32. #32
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by RudyL
    That does not work. In fact, if I click on cancel the word document does not close at all.. wierd..
    How does it not work? It sets the actual program (word) as invisible. You shouldnt see word at all. It should be placed right after you create the instance of word.

  33. #33
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by jhermiz
    How does it not work? It sets the actual program (word) as invisible. You shouldnt see word at all. It should be placed right after you create the instance of word.
    I still get a flicker, or flash of the word object after the ok button is clicked, as it is closing the object.. It isn't major, but it is anoying. The new problem I posted is a much bigger problem. Not sure why it did that.
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  34. #34

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    Apparently I never tested clicking the Cancel button. Anyhow with the program the way it is now, if you click Cancel the Word doc will show up and stay open, but only until you click the OK button on the The spelling check is complete. MsgBox. That behavior can be corrected by adding an objWord.Visible = False line. Where you place that line is important.

    VB Code:
    1. objDoc.Content = Text1.Text
    2.     objDoc.CheckSpelling
    3.     objWord.Visible = False

    BTW I assume you see a "flash" because you have a slow PC.

  35. #35
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by MartinLiss
    Apparently I never tested clicking the Cancel button. Anyhow with the program the way it is now, if you click Cancel the Word doc will show up and stay open, but only until you click the OK button on the The spelling check is complete. MsgBox. That behavior can be corrected by adding an objWord.Visible = False line. Where you place that line is important.

    VB Code:
    1. objDoc.Content = Text1.Text
    2.     objDoc.CheckSpelling
    3.     objWord.Visible = False

    BTW I assume you see a "flash" because you have a slow PC.
    Ok, I had the .visible = flase in the wrong place. That fixed the ignore thing..

    The flashing part though.. You almost hade me on the speed of my pc except that I have a Pentium 2.6 gig processor so I do not think that is the culprit..
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  36. #36
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: VB - Spell Check a Textbox

    Originally posted by MartinLiss
    Add this code to a command button or popup menu item.

    VB Code:
    1. Dim objWord As Object
    2.     Dim objDoc  As Object
    3.     Dim strResult As String
    4.    
    5.     'Create a new instance of word Application
    6.     Set objWord = CreateObject("word.Application")
    7.  
    8.     Select Case objWord.Version
    9.         'Office 2000
    10.         Case "9.0"
    11.             Set objDoc = objWord.Documents.Add(, , 1, True)
    12.         'Office XP
    13.         Case "10.0"
    14.             Set objDoc = objWord.Documents.Add(, , 1, True)
    15.         'Office 97
    16.         Case Else ' Office 97
    17.             Set objDoc = objWord.Documents.Add
    18.     End Select
    19.  
    20.     objDoc.Content = Text1.Text
    21.     objDoc.CheckSpelling
    22.  
    23.     strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    24.  
    25.     If Text1.Text = strResult Then
    26.         ' There were no spelling errors, so give the user a
    27.         ' visual signal that something happened
    28.         MsgBox "The spelling check is complete.", vbInformation + vbOKOnly
    29.     End If
    30.    
    31.     'Clean up
    32.     objDoc.Close False
    33.     Set objDoc = Nothing
    34.     objWord.Application.Quit True
    35.     Set objWord = Nothing
    36.  
    37.     ' Replace the selected text with the corrected text. It's important that
    38.     ' this be done after the "Clean Up" because otherwise there are problems
    39.     ' with the screen not repainting
    40.     Text1.Text = strResult
    41.  
    42.     Exit Sub
    Why dont you make this a function and pass a text box control?

    What's the latest and greatest code ?

  37. #37

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Re: VB - Spell Check a Textbox

    Originally posted by jhermiz
    Why dont you make this a function and pass a text box control?
    Be my guest.

    Originally posted by jhermiz
    What's the latest and greatest code ?
    Don't know about "greatest" but that's the latest.

  38. #38
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: Re: Re: VB - Spell Check a Textbox

    Originally posted by MartinLiss
    Be my guest.

    Don't know about "greatest" but that's the latest.

    Marty can you help here:

    http://www.vbforums.com/showthread.p...hreadid=295968

  39. #39
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: Re: Re: Re: VB - Spell Check a Textbox

    For anyone interested..

    I have taken marty's subroutine and converted it to a generic function taking in a text box as a parameter.

    Here is the code if anyone is interested:

    VB Code:
    1. Public Function CheckSpelling(t As TextBox)
    2. On Error GoTo Err_Handler
    3.  
    4.     Dim objWord As Object
    5.     Dim objDoc  As Object
    6.     Dim strResult As String
    7.    
    8.     'Create a new instance of word Application
    9.     If (Len(t.Text) = 0) Then
    10.         'nahhhhhhhhhhh
    11.     Else
    12.         App.OleRequestPendingTimeout = 999999
    13.         Set objWord = CreateObject("word.Application")
    14.         objWord.Visible = False
    15.        
    16.         Select Case objWord.Version
    17.             'Office 2000, xp, 2k3
    18.                 Case "9.0", "10.0", "11.0"
    19.                 Set objDoc = objWord.Documents.Add(, , 1, True)
    20.             'Office 97
    21.                 Case Else
    22.                 Set objDoc = objWord.Documents.Add
    23.         End Select
    24.  
    25.         objDoc.Content = t.Text
    26.         objDoc.CheckSpelling
    27.         objWord.Visible = False
    28.        
    29.         strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    30.         'correct the carriage returns
    31.         strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))
    32.  
    33.         If t.Text = strResult Then
    34.             ' There were no spelling errors, so give the user a
    35.             ' visual signal that something happened
    36.             MsgBox "The spelling check is complete.", vbInformation + vbOKOnly, "Spelling Complete"
    37.         End If
    38.    
    39.         'Clean up
    40.         objDoc.Close False
    41.         Set objDoc = Nothing
    42.         objWord.Application.Quit True
    43.         Set objWord = Nothing
    44.  
    45.         ' Replace the selected text with the corrected text. It's important that
    46.         ' this be done after the "Clean Up" because otherwise there are problems
    47.         ' with the screen not repainting
    48.         t.Text = strResult
    49.     End If
    50.  
    51. Done:
    52. Exit Function
    53.  
    54. 'in case user does not have word...
    55. Err_Handler:
    56. 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
    57. Resume Done
    58.  
    59. End Function

    Put this function in a module...

    To call it what I did was allow the end user to click the F7 key to do a spell check. You can modify this to fit your needs. I also only spell check the textbox that has the focus or is activated.

    YOu can also write code to go through a loop of textbox controls checking each one..

    Heres my call in the form key down event (set the keypreview property to true in the form as well)

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. On Error GoTo Err_Handler
    3.  
    4. Dim ctl As Control
    5. Set ctl = Me.ActiveControl
    6.  
    7. If KeyCode = vbKeyF7 And TypeOf ctl Is TextBox Then
    8.     Call CheckSpelling(ctl)
    9. Else
    10.     'do nothing
    11. End If
    12.  
    13. Done:
    14. Exit Sub
    15.  
    16. Err_Handler:
    17. MsgBox Err.description, vbCritical, "Error #: " & Err.Number
    18. Resume Done
    19. End Sub

    To loop through a bunch of text box controls try this:

    VB Code:
    1. Dim ctl As Control
    2.  
    3. For each ctl in Me.Controls
    4.   if TypeOf ctl is TextBox then
    5.      CheckSpelling(ctl)
    6.   end if
    7. next ctl

    Enjoy

  40. #40
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Re: VB - Spell Check a Textbox

    Quote 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!

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width