Results 1 to 5 of 5

Thread: SPELL CHECK and WORD

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    SPELL CHECK and WORD

    We just started using WORD to SPELL CHECK a textbox from VB.

    I have noticed, as well as some users testing it out, that if they have WORD open already (like sending an OUTLOOK e-mail or actually editing a WORD doc), the spell check window doesn't appear on top of our application. Things kind of get stuck...

    They have to use TASK MANAGER to kill our app - which then causes the WORD app to appear on screen - along with the spell check box, with our TEXTBOX info sitting in WORD.

    This was our first attempt at automation, so I'm sure we missed some key point somewhere...

    Thanks for the help.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Find any post by Martin Liss, his signature has a link that shows how to spellcheck with word. The procedure might even be in the Code Bank.

    For now, instead of killing the app use Alt-Tab to get to the spell check window.

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    I used the code in the MARTIN LISS posting - from his signature/code bank. That's what has me so puzzled...

    ALT-TAB didn't seem to work - I'll try to duplicate problem here and see if ALT-TAB does work...

    As far as automation goes - when you "start an instance" of WORD and WORD is already running, are you becoming part of that instance (since WORD is a MDI-parent/child kind of app??). Should I be killing the WORD app at the exit of my app, if I didn't really start it?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I havent seen Martins code but what I do is check to see if
    Word is running and if it is I attach my Word application object to
    it. If its not running I create a new one.

    Nothing new there, but when I start manipulating Word I set its
    visible property to false. Then I make the window minimized and
    set up the spell checking dialog box. Set its visible property to
    true and then display the spellchecking dialog box. I havent run
    into any issues yet so I think its stable. Maybe try something like
    this will work for you.

    HTH
    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

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    RobDog888

    This has been our first venture into automation - so I'm unclear on how to actually perform the changes you suggest.

    This is the actual function that I ripped from the MartinLiss posting. We changed the objWord to a PUBLIC object so that it would persist - allowing subsequent calls to CHECKSPELLING to be faster. And we put the CLOSE WORD logic in QUERY UNLOAd

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

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3. Debug.Print "Form_QueryUnload with State="; gbytState
    4.  
    5. If Not (objWord Is Nothing) Then
    6.     Debug.Print "Form_QueryUnload>Word QUIT"
    7.     objWord.Application.Quit True
    8. End If
    9. Set objWord = Nothing
    10.  
    11. If gbytState >= 5 Then
    12.     If setState(7) <> 7 Then Cancel = True
    13. End If
    14.  
    15. End Sub

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