Create word table using windows form RRS feed

  • Question

  • Hi,


    I am using Word 2007 with VSTOSE. I am new to VSTO and I am trying to create a word table using windows form. I am displaying a form at Startup and getting No. of cols & No. of rows from 2 text boxes as input. Then when I click the create button the table should be created. I am using the following code in the command button.


    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim mydoc As New Word.Document

    mydoc.Tables.Add(mydoc.selection.range, TextBox1.Text, TextBox2.Text)

    End Sub

    End Class


    But I am getting the error "Missing error exception was unhandled by user code".


    Can anyone help me on this.


    Thanks in advance

    Wednesday, September 12, 2007 5:43 PM


  • Hi Mohan,


    You should not use to new to create a document. Use the following code to get the current document’s handle.

    Code Snippet
    Dim mydoc as Word.Document = Me.Application.ActiveDocument







    Monday, September 17, 2007 2:13 AM