We help IT Professionals succeed at work.

Spell Check VB6 with MS Word

al4629740
al4629740 asked
on
73 Views
Last Modified: 2020-07-21
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.
Comment
Watch Question

Protect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Does this code work with the latest version of Office 365 apps?
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I have no way of testing that. If you do then please make a comment one way or the other in the article.

Author

Commented:
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
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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.

Author

Commented:
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?
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Using the article's code without modification, this is what I see. Can you show me a picture of yours?
2020-07-20_14-49-10.png

Author

Commented:
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?

Author

Commented:
Nothing comes up on the press


Author

Commented:
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.
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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

Author

Commented:
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
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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.
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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.

Author

Commented:
that would be great if you could assist but let me pose this as a new question.