How to use MS Word’s Spelling Corrector within VB
Posted on August 10, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 'MS Office - How to use MS Word's Spelling Corrector within VB 'If you would like to incorporate a spellings corrector in your VB app, it would 'take you quite a long time, this trick shows you in a simple example how to use 'MS Word´s Spelling Corrector within VB. 'Create a new project with one form. Put a 'CommandButton and a TextBox on it. 'Set the following properties of the textbox: '"Height = a couple of lines" Multiline=true 'ScrollBars=Vertical 'Code Private Sub Command1_Click() Text1 = SpellCheck(Text1) End Sub Public Function SpellCheck(ByVal IncorrectText$) As String Dim Word As Object, retText$ On Error Resume Next ' Create the Object and open Word Set Word = CreateObject("Word.Basic") ' Change the active window to Word, and insert the text from Text1 into Word. Word.AppShow Word.FileNew Word.Insert IncorrectText ' Runs the Speller Corrector Word.ToolsSpelling Word.EditSelectAll ' Trim the trailing character from the returned text. retText = Word.Selection$() SpellCheck = Left$(retText, Len(retText) - 1) ' Close the Document and return to Visual Basic. Word.FileClose 2 Show 'Set the word object to nothing to liberate the occupied memory Set Word = Nothing End Function 'This uses WordBasic so that you can use this tip with older versions of Word as 'well. |