Hi friends,
Can any one let me know how to install multiple tables into a word document using VB please?
I can insert a table using following coding, but when I add the second table, it always insert a second table into the first table.
Dim wrdDoc As Word.Document
Dim wrdSelection As Word.Selection
Dim wrdApp As Word.Application
Set wrdApp = New Word.Application
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.Select
Set wrdSelection = wrdApp.Selection
wrdSelection.TypeText "table1"
wrdApp.Selection.TypeParagraph
wrdDoc.Tables.Add wrdSelection.Range, NumRows:=1, NumColumns:=5
With wrdDoc.Tables(1)
.Cell(1, 1).Range.InsertAfter "col1"
.Cell(1, 2).Range.InsertAfter "col2"
.Cell(1, 3).Range.InsertAfter "col3"
.Cell(1, 4).Range.InsertAfter "col4"
.Cell(1, 5).Range.InsertAfter "col5"
End With
wrdSelection.TypeText "table2"
wrdApp.Selection.TypeParagraph
wrdDoc.Tables.Add wrdSelection.Range, NumRows:=1, NumColumns:=5
With wrdDoc.Tables(2)
.Cell(1, 1).Range.InsertAfter "col1"
.Cell(1, 2).Range.InsertAfter "col2"
End With
Can any one let me know how to install multiple tables into a word document using VB please?
I can insert a table using following coding, but when I add the second table, it always insert a second table into the first table.
Dim wrdDoc As Word.Document
Dim wrdSelection As Word.Selection
Dim wrdApp As Word.Application
Set wrdApp = New Word.Application
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.Select
Set wrdSelection = wrdApp.Selection
wrdSelection.TypeText "table1"
wrdApp.Selection.TypeParagraph
wrdDoc.Tables.Add wrdSelection.Range, NumRows:=1, NumColumns:=5
With wrdDoc.Tables(1)
.Cell(1, 1).Range.InsertAfter "col1"
.Cell(1, 2).Range.InsertAfter "col2"
.Cell(1, 3).Range.InsertAfter "col3"
.Cell(1, 4).Range.InsertAfter "col4"
.Cell(1, 5).Range.InsertAfter "col5"
End With
wrdSelection.TypeText "table2"
wrdApp.Selection.TypeParagraph
wrdDoc.Tables.Add wrdSelection.Range, NumRows:=1, NumColumns:=5
With wrdDoc.Tables(2)
.Cell(1, 1).Range.InsertAfter "col1"
.Cell(1, 2).Range.InsertAfter "col2"
End With