Solved

Spell Check in VB6

Posted on 2016-11-25
13
112 Views
Last Modified: 2016-11-29
I need to spell check a VB6 text box. I asked this question here. Was directed to:
https://www.experts-exchange.com/articles/8678/Spell-check-a-VBA-or-VB6-ActiveX-textbox.html
Or:
http://tinyurl.com/ha7heas

I wrote a little test app. Just a text box and a command button. Compiled to an exe. The spell check exe works fine in XP. In Win7, nothing happens. No error. Nothing.

I can't debug in Win7 obviously.

Would it be convenient if I copied the source code from the above link here?
0
Comment
Question by:NormaPosy
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41902061
The best way here is talk to the author.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41902102
Sorry but since I still use XP I won't be able to help find out what's wrong when run in Win 7. You may however find techniques in this article of mine on debugging that will help find the problem.
0
 

Author Comment

by:NormaPosy
ID: 41902119
Martin: VB6 won't run under Win7. At least that is what I have been told. Never tried it. (That's a lot of CDs to load just to find out.) There's a technique I have used to get around this. Back in XP, Define an error integer iErr. Sprinkle "Err = 1" (2, 3, 4, etc) throughout the code. Just before exiting, display a MsgBox showing iErr. At least that will tell me how far the thing got.

Thing is, under Win7 it doesn't throw up any errors. It just doesn't do anything.

The code invokes Word's spell checker. It first determines the resident version of Word. I am thinking that the "Cases" in the code don't include versions past when the code was created. I will look at that. There should be an "Else" I can use to tell me "Word not found". Or something like that.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 46

Accepted Solution

by:
Martin Liss earned 250 total points
ID: 41902404
VB6 won't run under Win7
Isn't that what you are using?

I am thinking that the "Cases" in the code don't include versions past when the code was created.
Note line 8 to 10 from the current code.
    Select Case objWord.version
        'Office 2000 and later
        Case "9.0", "10.0", "11.0", "14.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

0
 

Author Comment

by:NormaPosy
ID: 41902554
Martin: I develop and compile on an XP machine. The exe runs fine there. On a Win7 machine, when I run the exe, nothing at all happens. No message box, no error report, nothing.

Yes, I think my version of Word is not included in those lines of code. But I don't get that message box under line 9 either. I will have to investigate and get back here.
0
 
LVL 8

Assisted Solution

by:Bob Hoffman
Bob Hoffman earned 125 total points
ID: 41903122
I have a similar solution working fine on Win7 and Win 10. Couple things to check.

>> is the spell check pop-up behind your main form?
>> open the task manager, is word running?
>> try turning off UAC


here's my function:

Public Function SpellCheck(strText As String) As String

    Dim oWord As Word.Application
    Dim oTmpDoc As Word.Document
   
    Screen.MousePointer = vbHourglass
    On Error GoTo Failed
    Err.Clear
   
    'Create a Word document object...
    App.OleRequestPendingTimeout = 999999
    Set oWord = CreateObject("Word.Application")
    oWord.Visible = False
   
    Set oTmpDoc = oWord.Documents.Add(, , 1, True)

    Screen.MousePointer = vbDefault
   
    'Assign the text to the document and check spelling.
    With oTmpDoc
        .Content.Text = Trim$(strText)
        .Activate
        oWord.Visible = False
       
        'Bring spell check forward
        Dim lngHandle As Long
        lngHandle = FindWindow(vbEmpty, "Document1 - MIcrosoft Word")
        If lngHandle <> 0 Then
            Dim lngRet As Long
            lngRet = BringWindowToTop(lngHandle)
        End If
       
        .CheckSpelling
        oWord.Visible = False
       
        'After user has made changes, get text back...
        SpellCheck = Left(.Content.Text, Len(.Content.Text) - 1)

        'Close the document and exit Word...
        oWord.Visible = False
        .Close False '= wdDoNotSaveChanges
    End With
   
    'Clean up
    Set oTmpDoc = Nothing
    oWord.Visible = False
    oWord.Application.Quit (False)
    Set oWord = Nothing

    Exit Function
Failed:
    Set oTmpDoc = Nothing
    Set oWord = Nothing
    Screen.MousePointer = vbDefault

    MsgBox "SpellCheck() failed! Error is: " & Trim$(Err.Description), vbCritical, "Critical error"
End Function
0
 
LVL 9

Assisted Solution

by:Karen
Karen earned 125 total points
ID: 41903409
If you have not already, you should change
 Case "Else"
to
 Case Else
1
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41903412
If you have not already, you should change
 Case "Else"
to
 Case Else
OMG, I never, and no one else as far as I know, has ever noticed that mistake!! I will update my article now. Thank you.
0
 
LVL 9

Expert Comment

by:Karen
ID: 41903446
dontcha hate bugs like that, Martin... when you notice them and think, "how the heck have I not noticed that before????" :D
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41903451
I know. In my case I can chalk it up to a "senior moment" but the article was first published 5 years ago and it has gotten lots of views and likes since then and nobody has said a word.
0
 

Author Closing Comment

by:NormaPosy
ID: 41904875
My version of word is "15.0". Had to add it to the case statement.

How many times have I stared buggy eyed at code not seeing the screw up. Then you call another set of eyeballs over and  "pop" - there it is. "Else" indeed!!

Thank you to everyone.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41904878
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0
 
LVL 9

Expert Comment

by:Karen
ID: 41906600
I'm glad my eyeballs could be of assistance 8-)
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 54
VBA error replacing data 6 40
SQL VB connection works in one PC and doesn't in another 15 64
Help me. 3 54
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question