Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

Spell Check VB6 with MS Word

I have a form in VB6 that has a narrative text box in it.  I need to spell check that box whenever a user types their content into that field?  Is there a way to use the spell check from MS Word to accomplish this?  If so, could you provide me with what I need to exactly do?  Thank you in advance.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of al4629740

ASKER

Does this code work with the latest version of Office 365 apps?
I have no way of testing that. If you do then please make a comment one way or the other in the article.
On your article is says "The code expects an ActiveX textbox named "Text1" and an ActiveX command button named "SpellCheck"

Is this basically the Textbox found in the VB6 program on the toolbox
In the code as written, both are expected to be ActiveX controls. Is that a problem? If so let me know and I can probably help modify the code.
One more thing on your article.  When I run the code, the dialog box for spell check does not appear or seems to be recessed in the background.  Is there a way to make sure it comes to the front of the application once the spell check button is pressed?
Using the article's code without modification, this is what I see. Can you show me a picture of yours?
User generated image
My screen does not show the spelling box.  It is hidden.  However when I push Alt+Tab, then I can locate it and make it appear.  It is completely hidden before that.
I guess my question is there a way to bring that dialog box to the front?
Nothing comes up on the press

User generated image
I found the problem!  It comes up behind my form and it locks the form so you can't move it.  So then I never see it because I can't even move the form.  You'll notice the same thing on yours if you try to move Form1 while the spell check screen is open.

In my case I might have to move the form via the program somehow when the spell check is running.
I believe I've found a solution. This shows the beginning of the code. I added line 20.
Private Sub SpellCheck_Click()

    Dim objWord As Object
    Dim objDoc  As Object
    Dim strResult As String
    Const QUOTE = """"
    
    On Error GoTo ErrorRoutine

    App.OleRequestPendingTimeout = 999999
    Set objWord = GetObject("Word.Application")
    If TypeName(objWord) <> "Nothing" Then
        ' Word is already open
        Set objWord = GetObject(, "Word.Application")
    Else
        ' Create an instance of Word
        Set objWord = CreateObject("Word.Application")
    End If
    
    Me.Show
    
    Select Case objWord.version
        'Office 2000 and later
        Case "9.0", "10.0", "11.0", "14.0", "15.0"
            Set objDoc = objWord.Documents.Add(, , 1, True)
        'Office 97
        Case "8.0"
            Set objDoc = objWord.Documents.Add
        Case Else
            MsgBox "Sorry but your version of Word seems to be " & QUOTE & objWord.version _
                   & QUOTE & " and that version is not currently supported.", vbOKOnly + vbExclamation, "Spelling Checker"
            Exit Sub
    End Select

Open in new window

That didn't work because it shows the form still in front of the spell checker.  It seems the only way around it is to Hide the Form and then make it appear after the spell checker session is over
Yes I agree I had Me.Hide just before the App.OleRequestPendingTimeout = 999999 line but when I tried it without it it still seemed to work so I deleted it.
Other possible solutions:

  • If your form's StartUpPosition property is set to 2 - CenterScreen, change it to 0 - WindowsDefault
  • Open your form, manually move it to where it's conveniently out of the way of the spellcheck window and then use code that you can find on the web to save the form's position and open the form at that position the next time.
  • Dim a Long variable and at the top of the command button code save the form's Left value, change the form's Left value to 0 and when the spellcheck code is done set Left back to the saved left value.

If you'd like me to I'll spend some time trying to find out how to move the spellcheck window from behind your form.
that would be great if you could assist but let me pose this as a new question.