Connecting Tech Pros Worldwide Forums | Help | Site Map

How to add multiple tables to MS word document using vb.net?

Member
 
Join Date: Mar 2007
Posts: 40
#1: Nov 21 '08
i want to know how multiple tables are added to the MS word document using vb.net

i wrote following code to insert one table in MS word document using vb.net
1.opened MS word document
2.inserted one 3x3 table

Dim App As New Word.Application()
Dim Doc As Word.Document = App.Documents.Add()
Dim oTable1 As Word.Table
Dim Range As Word.Range

Range = Doc.Paragraphs.Add().Range
otable1 = Range.Tables.Add(Range:=App.Selection.Range,
NumColumns:=3, NumRows:=3)
With oTable1
.Cell(1, 1).Range.Text = "Code"
.Cell(1, 2).Range.Text = "Description"
.Cell(1, 3).Range.Text = "Units"
.Cell(2, 1).Range.Text = "1"
.Cell(2, 2).Range.Text = "2"
.Cell(2, 3).Range.Text = "3"
.Cell(3, 1).Range.Text = "4"
.Cell(3, 2).Range.Text = "5"
.Cell(3, 3).Range.Text = "6"
End With

MsgBox("saved1")
Doc.SaveAs("f:\qwerty1.doc")
Doc.Close()

i am able to insert one table,but when i am trying to insert multiple tables,
the tables are getting inserted wrongly like,one table is inserted into another table

i want code for inserting multiple tables in MS Word document using vb.net

Reply