Using Words Spellcheck and grammer check with your windows Forms application

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

 

Comments

# re: Using Words Spellcheck and grammer check with your windows Forms application
Gravatar I would like to have spellcheck and grammer ckeck
Left by alberta on 1/20/2009 8:29 PM
# re: Using Words Spellcheck and grammer check with your windows Forms application
Gravatar I think I will try to recommend this post to my friends and family, cuz it’s really helpful.
Left by street lights on 11/12/2009 1:54 AM
# re: Using Words Spellcheck and grammer check with your windows Forms application
Gravatar One of my customers wanted to add spell check functionality to their windows
Left by christian louboutin on 11/12/2009 11:33 PM
# re: Using Words Spellcheck and grammer check with your windows Forms application
Gravatar check this article that was very helpful .
Left by christian louboutin sale on 11/16/2009 1:28 AM
# Mr
Gravatar thanks for your nice experience to share with us .Really awesome article with plenty of informative things to be known for us .Keep posting more articles like this.

Left by Colon Cleanse on 11/21/2009 2:47 AM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

 

Preview Your Comment.