HOWTO: VB3: Use the Word SpellChecker Via OLE Automation

Last reviewed: September 29, 1997
Article ID: Q114020
The information in this article applies to:

- Microsoft Visual Basic programming system for Windows, version 3.0 - Microsoft Word for Windows, version 6.0

SUMMARY

This article shows by example how to use the built-in SpellChecker from Microsoft Word version 6.0 to check the spelling of the contents of a text box in a Microsoft Visual Basic version 3.0 application.

The example takes the contents of a Visual Basic text box, inserts the text into a Word document, and then spell checks the text. After the spell check is complete, you insert the spell checked text from the Word document back into the Visual Basic text box.

MORE INFORMATION

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a text box (Text1) and command button (Command1) to Form1.

  3. Set the multiline property of the text box to true.

  4. Add the following code to the Form_Load event:

          Sub Form_Load()
             Command1.Caption = "Press to SpellCheck"
             Text1.Text = "The Seattle SuperSonics ar goig all the wa _
             this yeer!!"
          End Sub
    
    

  5. Place the following code in the Command1 Click event procedure of Form1:

          Sub Command1_Click ()
             Dim oWDBasic As Object
             Dim sTmpString As String
             Set oWDBasic = CreateObject("Word.Basic")
             oWDBasic.FileNew
             oWDBasic.Insert Text1.Text
             On Error Resume Next
             oWDBasic.ToolsSpelling
             oWDBasic.EditSelectAll
             oWDBasic.SetDocumentVar "MyVar", oWDBasic.Selection
             sTmpString = oWDBasic.GetDocumentVar("MyVar")
             Text1.Text = Left(sTmpString, Len(sTmpString) - 1
             MsgBox "Spell Check is complete"
          End Sub
    
    

  6. Run the program.

Click the Command1 button, and go through the following sequence of corrections:

   SuperSonics(Ignore)
   ar(Change to are)
   goig(Change to going)
   wa(Change to way)
   yeer(Change to year)

After the last correction, you will get a Message box telling you that the Spell Check is complete. The results inserted back into the Text1 text box should say this:

   The Seattle SuperSonics are going all the way this year!!
Keywords          : IAPOLE vb3only vbwin GnrlVb kbprg kbfasttip
Technology        : kbole kbvba
Version           : WINDOWS:3.0
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.