Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 101

Thread: VB - Spell Check a Textbox

  1. #41
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    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?

  2. #42

  3. #43
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    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?

  4. #44

  5. #45
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    Re: VB - Spell Check a Textbox

    I am using VB.NET. Do you know of any postings on spell checking in .NET?
    Brenda

    If it weren't for you guys, where would I be?

  6. #46
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Question Re: VB - Spell Check a Textbox

    Hi!
    Does anyone have any idea how to make the spell and grammar check multilanguage?

    Thanks!

  7. #47

  8. #48
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Re: VB - Spell Check a Textbox

    Check this out for spell checking in VB.NET...

    http://msdn.microsoft.com/office/und...dspellchkr.asp

    jb.

  9. #49
    New Member
    Join Date
    Feb 2005
    Posts
    4

    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

  10. #50

  11. #51
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Resolved Re: VB - Spell Check a Textbox

    Got it! This is what I got in the macro..

    VB Code:
    1. Sub SpellCheck()
    2. '
    3. ' SpellCheck Macro
    4. '
    5.     Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    6.     Selection.LanguageID = wdGerman
    7.     Selection.NoProofing = False
    8.     Application.CheckLanguage = False
    9. End Sub


    I'll try it out in the project.
    Thank you! That was a great idea!

    jb
    Last edited by jbhan; Feb 15th, 2005 at 08:44 PM.

  12. #52
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: VB - Spell Check a Textbox

    can i use that in my html editor?

  13. #53
    Lively Member
    Join Date
    Mar 2003
    Posts
    126

    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.

  14. #54

  15. #55
    Lively Member
    Join Date
    Mar 2003
    Posts
    126

    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

  16. #56
    Lively Member
    Join Date
    Mar 2003
    Posts
    126

    Re: VB - Spell Check a Textbox

    I don't think I'm missing anything. This is code I'm using:

    VB Code:
    1. Public Function CheckSpelling(t As textbox)
    2. 'SpellCheck Function
    3. 'taken from [url]http://www.vbforums.com/showthread.php?t=246451[/url]
    4. On Error GoTo Err_Handler
    5.  
    6.     Dim objWord As Object
    7.     Dim objDoc  As Object
    8.     Dim strResult As String
    9.    
    10.     'Create a new instance of word Application
    11.     App.OleRequestPendingTimeout = 999999
    12.     Set objWord = CreateObject("word.Application")
    13.     objWord.Visible = False
    14.    
    15.     Set objDoc = objWord.Documents.Add(, , 1, True)
    16.  
    17.     objDoc.Content = t.text
    18.     objDoc.CheckSpelling
    19.     objWord.Visible = False
    20.    
    21.     strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
    22.     'correct the carriage returns
    23.     strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))
    24.  
    25.     If t.text = strResult Then
    26.         ' There were no spelling errors, so give the user a
    27.         ' visual signal that something happened
    28.         MsgBox "The spell check is complete!", vbInformation + vbOKOnly, "Spelling Complete"
    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.     t.text = strResult
    41.  
    42. Exit Function
    43.  
    44. 'in case user does not have word...
    45. Err_Handler:
    46. 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
    47.  
    48. End Function

  17. #57

  18. #58
    Lively Member
    Join Date
    Mar 2003
    Posts
    126

    Re: VB - Spell Check a Textbox

    Ok - thanks anyway Martin.

  19. #59
    Member
    Join Date
    Nov 2002
    Posts
    53

    Re: VB - Spell Check a Textbox

    Sorry I was unable to find a fix for this.

  20. #60
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    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.
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  21. #61

  22. #62
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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
    Last edited by hdtvluvr; Nov 20th, 2005 at 04:27 PM.

  23. #63

  24. #64
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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.

  25. #65
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: VB - Spell Check a Textbox

    You have to set a reference to WORD in the project first.
    Microsoft Word x.0 Object Library
    Use whatever version that you have. I have Office XP, which is 10.0

  26. #66
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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.

  27. #67
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    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.
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  28. #68

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

    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.

  29. #69
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    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.
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  30. #70

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

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

  31. #71
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    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.
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  32. #72

  33. #73
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    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!
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  34. #74
    New Member
    Join Date
    Jun 2006
    Posts
    1

    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.

  35. #75
    New Member
    Join Date
    Mar 2007
    Posts
    1

    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!

  36. #76

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

    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!
    I 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.

  37. #77
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  38. #78
    New Member
    Join Date
    Apr 2007
    Posts
    2

    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

  39. #79
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: VB - Spell Check a Textbox

    Word 97 did not support the arguments as 200 and newer does.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  40. #80
    New Member
    Join Date
    Apr 2007
    Posts
    2

    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

Page 2 of 3 FirstFirst 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