Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WORD vba CENTER a Table

Status
Not open for further replies.

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
 
...
With Goods
.Rows.Alignment = wdAlignRowCenter
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - You are so nice to help out with everything I work on, I really appreciate the assistance sight unseen.

I really dig into the code for the answer but have a little problem understanding command format. I had Slection.Tables(1).Rows.Alignment = wdAlignRowCenter and I hope with more experience that I will get a better understanding.

Thank-you - I need your email address but think it is a no-no on the forum.

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top