having issues using words spell checker vb.net

Hello experts i have referenced microsoft words spell checker in my vb.net app.  My problem is that when I use the spell check feature any change I make to a selected spelling, microsoft word quickly pops up then closes.  It is very noticeable and I was wondering if there is a way to keep it from popping up or making it less noticeable.  Else is there a free spell checker tool that I can use within my vb.net app?  My code is below.

 Private Sub SpellOrGrammarCheck(ByVal blnSpellOnly As Boolean)

        Try
            ' Create Word and temporary document objects.
            Dim objWord As Object
            Dim objTempDoc As Object
            ' Declare an IDataObject to hold the data returned from the
            ' clipboard.
            Dim iData As IDataObject

            ' If there is no data to spell check, then exit sub here.
            If txtpolicy.Text = "" Then
                MessageBox.Show("Please enter some text")
                Exit Sub
            End If

            objWord = New Word.Application
            objTempDoc = objWord.Documents.Add
            objWord.Visible = False

            ' Position Word off the screen...this keeps Word invisible
            ' throughout.
            objWord.WindowState = 0
            objWord.Top = -3000

            ' Copy the contents of the textbox to the clipboard
            Clipboard.SetDataObject(txtpolicy.Text)

            ' With the temporary document, perform either a spell check or a
            ' complete
            ' grammar check, based on user selection.
            With objTempDoc
                .Content.Paste()
                .Activate()
                If blnSpellOnly Then
                    .CheckSpelling()
                Else
                    .CheckGrammar()
                End If
                ' After user has made changes, use the clipboard to
                ' transfer the contents back to the text box
                .Content.Copy()
                iData = Clipboard.GetDataObject
                If iData.GetDataPresent(DataFormats.Text) Then
                    txtpolicy.Text = CType(iData.GetData(DataFormats.Text), _
                        String)
                End If
                .Saved = True
                .Close()
            End With

            objWord.Quit()

            MessageBox.Show("The spelling check is complete.", _
                "Spell Checker", MessageBoxButtons.OK, _
                MessageBoxIcon.Information)

            ' Microsoft Word must be installed.
        Catch COMExcep As COMException
            MessageBox.Show( _
                "Microsoft Word must be installed for Spell/Grammar Check " _
                & "to run.", "Spell Checker")

        Catch Excep As Exception
            MessageBox.Show("An error has occured.", "Spell Checker")

        End Try

    End Sub
tentavariousAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
objWord.Visible = False

Bob
0
tentavariousAuthor Commented:
I had it set to false, what happens is the background of word shows up for a split second then disappears.
0
Bob LearnedCommented:
Yeah, I missed that one.  :(

What line causes the background to show up?

Bob
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

tentavariousAuthor Commented:
Ok, after I ran my program a cupple times it seems to disappear faster now, but it still shows up in the taskbar, anyway to stop it?
0
Bob LearnedCommented:
You didn't answer my question.

Bob
0
tentavariousAuthor Commented:
Its within this with block, the .checkspelling is where is starts
  With objTempDoc
                .Content.Paste()
                .Activate()
                If blnSpellOnly Then
                    .CheckSpelling()
                Else
                    .CheckGrammar()
                End If
                ' After user has made changes, use the clipboard to
                ' transfer the contents back to the text box
                .Content.Copy()
                iData = Clipboard.GetDataObject
                If iData.GetDataPresent(DataFormats.Text) Then
                    txtpolicy.Text = CType(iData.GetData(DataFormats.Text), _
                        String)
                End If
                .Saved = True
                .Close()
            End With
0
Bob LearnedCommented:
Here is what I came up with:

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop

<Flags()> _
Public Enum SpellCheck
  Spelling = &H1
  Grammar = &H2
  Spelling_Grammer = Spelling Or Grammar
End Enum

Public Class WordSpellChecker

  Public Shared Function DoCheck(ByVal text As String, ByVal mode As SpellCheck) As String

    Dim app As Word.Application
    Dim doc As Word.Document

    Try


      ' If there is no data to spell check, then exit sub here.
      If text.Length = 0 Then
        MessageBox.Show("Please enter some text")
        Exit Function
      End If

      ' Create Word and temporary document objects.
      app = New Word.Application
      doc = app.Documents.Add()

      app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
      app.Visible = False

      ' Copy the contents of the textbox to the clipboard
      Clipboard.SetDataObject(text)

      ' With the temporary document, perform either a spell check or a
      ' spell check/grammar check, based on user selection.
      doc.Content.Paste()
      doc.Activate()

      Select Case mode

        ' Grammar?
        Case SpellCheck.Grammar
          doc.CheckGrammar()

          ' Spelling?
        Case SpellCheck.Spelling
          doc.CheckSpelling()

          ' Spelling/Grammar?
        Case SpellCheck.Spelling_Grammer
          doc.CheckGrammar()
          doc.CheckSpelling()
      End Select       'mode

      app.Visible = False

      ' After user has made changes, use the clipboard to
      ' transfer the contents back to the text box
      doc.Content.Copy()

      ' Declare an IDataObject to hold the data returned from the
      ' clipboard.
      Dim iData As IDataObject = Clipboard.GetDataObject
      If iData.GetDataPresent(DataFormats.Text) Then
        text = iData.GetData(DataFormats.Text).ToString()
      End If

      doc.Close(saveChanges:=False)

      app.Quit()

      MessageBox.Show("The spelling check is complete.", _
       "Spell Checker", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch ex As COMException

      ' Microsoft Word must be installed.
      MessageBox.Show( _
         "Microsoft Word must be installed for Spell/Grammar Check to run.", _
        "Spell Checker")

    Catch ex As Exception

      MessageBox.Show("An error has occured.", "Spell Checker")

    Finally

      If Not app Is Nothing Then
        Marshal.ReleaseComObject(app)
      End If

      If Not doc Is Nothing Then
        Marshal.ReleaseComObject(doc)
      End If

      GC.Collect()

    End Try

    Return text

  End Function  'SpellGrammarCheck

End Class

Example usage:
  Me.txtPolicy.Text = WordSpellChecker(Me.txtPolicy.Text, SpellCheck.Spelling)

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.