VB.net & Word

Hi

I using a multiline Textbox called TestSpelltextbox to enter text
e.g

Hello Me Name
This is a letter for
You

Regards

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
            .Documents.Add()
            .Selection.Text = TestSpelltextbox.Text
            .ActiveDocument.CheckSpelling()
            TestSpelltextbox.Text = wa.Selection.Text
            .ActiveDocument.Close(SaveChanges:=0)
            .Quit()
        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

Thanks
KevinfeeningAsked:
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.

KevinfeeningAuthor Commented:
Hi

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)
            
                  doc.Words.First.InsertBefore(TestTextBox.Text)            
                  doc.Activate()            
                  dlg = app.Dialogs.Item(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar)            
                  dlg.Show()            
                  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

0
KevinfeeningAuthor Commented:
so no answer
have I not put it in the correct sections
what is the next option
0
GrahamSkanRetiredCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

KevinfeeningAuthor Commented:
Thanks
I have attached a document with screen shots of what happensspellcheck.docx
0
KevinfeeningAuthor Commented:
Found problem the textbox causes it if I use Richtext is works
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
GrahamSkanRetiredCommented:
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.
0
KevinfeeningAuthor Commented:
TextBox causing error using richtextbox
0
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.