VB.net & Word


I using a multiline Textbox called TestSpelltextbox to enter text

Hello Me Name
This is a letter for


I then click button to check spelling

 Imports Microsoft.Office.Interop

Private Sub mSpellcheckButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mSpellCheckButton.Click

    Dim wa As New Word.Application

        With wa
            .Visible = False
            .Selection.Text = TestSpelltextbox.Text
            TestSpelltextbox.Text = wa.Selection.Text
        End With

        wa = Nothing    

End Sub

Open in new window

1.. when spell check is finished the text comes back in 1 line I would like it to stay as entered
2.. If I click the button twice the Spell check goes behind the form I need a way to make it stay in front like the bringtofront in Delphi
3.. If you hit cancel or ignore all with more than 1 error in spell check then click Close the text is removed from the TestSpelltextbox.text

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

KevinfeeningAuthor Commented:

I found the following Code and it fixes 3.. but still have the problem
1.. when spell check is finished the text comes back in 1 line I would like it to stay as entered
Imports Microsoft.Office.Interop
Imports System.Reflection

Public Class TestForm
    Private Sub TestTextBox_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestTextBox.Leave       
               Dim app As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
               If Not String.IsNullOrEmpty(TestTextBox.Text) Then            
                  app.Visible = False            
                  Dim template As Object = Missing.Value            
                  Dim newTemplate As Object = Missing.Value            
                  Dim documentType As Object = Missing.Value            
                  Dim visible As Object = False            
                  Dim dlg As Word.Dialog            
                  Dim doc As Microsoft.Office.Interop.Word._Document = app.Documents.Add(template, newTemplate, documentType, visible)
                  dlg = app.Dialogs.Item(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar)            
                  Dim first As Object = 0            
                  Dim last As Object = doc.Characters.Count - 1            
                  TestTextBox.Text = doc.Range(first, last).Text        
            End If        
             Dim saveChanges As Object = False        
             Dim originalFormat As Object = Missing.Value        
             Dim routeDocument As Object = Missing.Value        
             app.Quit(saveChanges, originalFormat, routeDocument)
     End Sub

End Class

Open in new window

KevinfeeningAuthor Commented:
so no answer
have I not put it in the correct sections
what is the next option
I don't use .net much, so, for speed, I tested your original code in VBA. I couldn't reproduce the problem.

I will try in VS2013
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

KevinfeeningAuthor Commented:
I have attached a document with screen shots of what happensspellcheck.docx
KevinfeeningAuthor Commented:
Found problem the textbox causes it if I use Richtext is works

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
Sorry, I couldn't get VS2013 working with Word. I last tried it in an earlier version of .net which I no longer have. Things seem to have changed since.
KevinfeeningAuthor Commented:
TextBox causing error using richtextbox
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.