WBURKERT
Technical User
- May 28, 2010
- 73
Here is a portion of code that is working nicely. I would like to center the table added at Bookmarks ("section_2"). I got the Table style and format working but need some help with centering the Table.
Sub Section_X_to_Word_Table_at_Bookmark_X()
'WORD variables
Dim docDest As Word.Document
Dim Goods As Word.Table
Dim oCell As Word.Cell
'EXCEL variables
Dim appXL As Excel.Application
Dim rngWithData As Excel.Range
Dim mySpreadsheet As Excel.Workbook
Dim aryWithData, i As Integer, j As Integer
'row/column counters
Dim RowCount As Long
Dim ColCount As Long
'****************************************************************************************
'****************************************************************************************
Set appXL = CreateObject("Excel.Application")
Set mySpreadsheet = GetObject("F:\Documents\ACME\Sec2.xls")
Set rngWithData = mySpreadsheet.Worksheets(1).Range("Print_Area")
RowCount = rngWithData.Rows.Count
ColCount = rngWithData.Columns.Count
Set docDest = Documents.Open("F:\Documents\ACME\ACME LIST with TOC.doc")
Set Goods = docDest.Tables.Add(docDest.Bookmarks("Section_2").Range, RowCount, ColCount)
With Goods
'.Range.Style = "greenbar"
'.Tables(1).Rows.Alignment = wdAlignRowCenter
.Columns(1).Width = InchesToPoints(1)
.Columns(2).Width = InchesToPoints(4)
.Columns(3).Width = InchesToPoints(1)
.Rows(1).Range.Font.Bold = True
End With
For Each oCell In Goods.Range.Cells
oCell.Range.Text = rngWithData.Cells(oCell.RowIndex, oCell.ColumnIndex).Value
Next
Set rngWithData = Nothing
Set Goods = Nothing
End Sub
Sub Section_X_to_Word_Table_at_Bookmark_X()
'WORD variables
Dim docDest As Word.Document
Dim Goods As Word.Table
Dim oCell As Word.Cell
'EXCEL variables
Dim appXL As Excel.Application
Dim rngWithData As Excel.Range
Dim mySpreadsheet As Excel.Workbook
Dim aryWithData, i As Integer, j As Integer
'row/column counters
Dim RowCount As Long
Dim ColCount As Long
'****************************************************************************************
'****************************************************************************************
Set appXL = CreateObject("Excel.Application")
Set mySpreadsheet = GetObject("F:\Documents\ACME\Sec2.xls")
Set rngWithData = mySpreadsheet.Worksheets(1).Range("Print_Area")
RowCount = rngWithData.Rows.Count
ColCount = rngWithData.Columns.Count
Set docDest = Documents.Open("F:\Documents\ACME\ACME LIST with TOC.doc")
Set Goods = docDest.Tables.Add(docDest.Bookmarks("Section_2").Range, RowCount, ColCount)
With Goods
'.Range.Style = "greenbar"
'.Tables(1).Rows.Alignment = wdAlignRowCenter
.Columns(1).Width = InchesToPoints(1)
.Columns(2).Width = InchesToPoints(4)
.Columns(3).Width = InchesToPoints(1)
.Rows(1).Range.Font.Bold = True
End With
For Each oCell In Goods.Range.Cells
oCell.Range.Text = rngWithData.Cells(oCell.RowIndex, oCell.ColumnIndex).Value
Next
Set rngWithData = Nothing
Set Goods = Nothing
End Sub