Geeks With Blogs

Shervin Shakibi's Blog blog

One of my customers wanted to add spell check functionality to their windows Form application.  knowing that everyone in their organization has Microsoft Office installed, I did not want to include word interop with the application. so I found a neat way of using words spellcheck. for more information you might want to check this article that was very helpful .

  Private Sub SpellAndGrammarCheck(ByVal YourTextbox As TextBox)

        Try

            Dim oWord As Object = Nothing

            Dim oDoc As Object = Nothing

            Dim oData As IDataObject = Nothing

            oWord = System.Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"))

 

           Dim  oDocuments as object = oWord.[GetType]().InvokeMember("Documents", _

                           BindingFlags.[Default] Or BindingFlags.GetProperty, _

                           Nothing, oWord, Nothing)

 

 

            oDoc = oDocuments.[GetType]().InvokeMember("Add", BindingFlags.[Default] _

                     Or BindingFlags.InvokeMethod, Nothing, oDocuments, Nothing)

            oWord.Visible = False

 

            oWord.WindowState = 0

            oWord.Top = -3000

            Clipboard.SetDataObject(YourTextbox.Text)

 

            With oDoc

                .Content.Paste()

                .Activate()

                .CheckGrammar()

                .Content.Copy()

                oData = Clipboard.GetDataObject

                If oData.GetDataPresent(DataFormats.Text) Then

                    YourTextbox.Text = CType(oData.GetData(DataFormats.Text), String)

                End If

                .Saved = True

                .Close()

            End With

            oWord.Quit()

            MsgBox("Spelling check complete!")

            'SPELLWORKING = True

        Catch COMEcep As COMException

            MsgBox("MS Word must be installed to perform spelling checks", , _

                   "Spell check is not available")

        Catch ex As Exception

            MsgBox("Error, Make sure you have MS word installed.", , ex.Message)

 

        End Try

End Sub

 

Posted on Wednesday, November 5, 2008 3:42 PM | Back to top


Comments on this post: Using Words Spellcheck and grammer check with your windows Forms application

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Shervin Shakibi | Powered by: GeeksWithBlogs.net