vodkha
04-01-2005, 09:54 AM
I'm trying to build multiply tables in word with data from an excel spread sheet.
for instance the first row of data in my spreadsheet will be in one table and the second row in another table. I started a code that creates a table in word but i don't know how to populate it with the data.
Private Sub MakeTable()
Dim objWd As Word.Application
Dim objDoc As Word.Document
Dim objRange As Word.Range
Set objWd = CreateObject("Word.Application")
objWd.Visible = True
Set objDoc = objWd.Documents.add
Set objRange = objDoc.Range(0, 0)
objDoc.Tables.add Range:=objRange, _
NumRows:=15, _
NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitContent
With objDoc
.Tables(1).Columns(1).Width = 150
.Tables(1).Columns(2).Width = 300
.Tables(1).Columns(1).Shading.BackgroundPatternColor = wdColorGray10
.Tables(1).Rows.Height = AutoFit
.Tables(1).Rows.Alignment = wdAlignRowCenter
.Tables(1).Cell(1, 1).Range = Sheet1.Cells(A, 1).Value
End With
End Sub
for instance the first row of data in my spreadsheet will be in one table and the second row in another table. I started a code that creates a table in word but i don't know how to populate it with the data.
Private Sub MakeTable()
Dim objWd As Word.Application
Dim objDoc As Word.Document
Dim objRange As Word.Range
Set objWd = CreateObject("Word.Application")
objWd.Visible = True
Set objDoc = objWd.Documents.add
Set objRange = objDoc.Range(0, 0)
objDoc.Tables.add Range:=objRange, _
NumRows:=15, _
NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitContent
With objDoc
.Tables(1).Columns(1).Width = 150
.Tables(1).Columns(2).Width = 300
.Tables(1).Columns(1).Shading.BackgroundPatternColor = wdColorGray10
.Tables(1).Rows.Height = AutoFit
.Tables(1).Rows.Alignment = wdAlignRowCenter
.Tables(1).Cell(1, 1).Range = Sheet1.Cells(A, 1).Value
End With
End Sub