Microsoft KB Archive/147818

= HOWTO: Use the Word 6.0 SpellChecker Via OLE Automation in Visual Basic =

Article ID: 147818

Article Last Modified on 2/21/2005

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Word 6.0 Standard Edition

-



This article was previously published under Q147818



SUMMARY
This article demonstrates 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 4.0 application.

The example takes the contents of a Visual Basic text box, inserts the text into a Word document, and then checks the spelling in 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.



Step-by-Step Example
 Start a new project in Visual Basic. Form1 is created by default. Add a text box (Text1) and CommandButton (Command1) to Form1. Set the multi-line property of the text box to true.  Add the following code to the Form_Load event: Private Sub Form_Load Command1.Caption = "Press to SpellCheck" Text1.Text = "The Seattle Mariners ar goig all the wa this yeer!!" End Sub   Place the following code in the Command1 Click event procedure of Form1: Private 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  Run the program.</ol>

Click the Command1 button, and go through the following sequence of corrections: <pre class="fixed_text">  Mariners(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: <pre class="fixed_text">  The Seattle Mariners are going all the way this year!!

Keywords: kbhowto kbnoupdate kb16bitonly KB147818

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.