dansyoz
02-18-2010, 04:57 AM
Hi
I am creating a number of tables via VBA in newly created documents.
The table creates fine and is populated from a multidimensional array - the number of dimensions depends on the particular table.
Everything works except I can't find a way to right align the numeric values in its respective column.
Sample code for a 2 column table (column 1 needs to be left aligned) to create it.
With tblSummary
.Columns(1).SetWidth ColumnWidth:=CentimetersToPoints(6), RulerStyle:=wdAdjustNone
.Columns(2).SetWidth ColumnWidth:=CentimetersToPoints(3), RulerStyle:=wdAdjustNone
.Rows.Alignment = wdAlignRowCenter
.Rows.SpaceBetweenColumns = CentimetersToPoints(0.38)
.Rows(1).Range.Font.Bold = wdToggle
.Rows(1).Range.Font.Name = "Arial"
.Rows(1).Range.Font.Size = 9
.Rows(1).Range.Font.Color = wdColorDarkRed
.Cell(1, 1).Range.Text = "Result"
.Cell(1, 2).Range.Text = "Count"
For j = 1 To UBound(gResSummArray, 2)
' Result text - need to left align
.Cell(j + 1, 1).Range.Text = gResSummArray(1, j)
' Count of results - need to right align
.Cell(j + 1, 2).Range.Text = gResSummArray(2, j)
.Rows(j + 1).Range.Font.Bold = False
.Rows(j + 1).Range.Font.Name = "Arial"
.Rows(j + 1).Range.Font.Size = 8
.Rows(j + 1).Range.Font.Color = wdColorBlack
Next j
.Sort ExcludeHeader:=True, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldAlphanumeric, _
casesensitive:=False, _
SortOrder:=wdSortOrderDescending
End With 'tblsummary
There is a header row.
Question
How can I do this without selecting the table ie. I am trying to avoid the Select.
Thanks
I am creating a number of tables via VBA in newly created documents.
The table creates fine and is populated from a multidimensional array - the number of dimensions depends on the particular table.
Everything works except I can't find a way to right align the numeric values in its respective column.
Sample code for a 2 column table (column 1 needs to be left aligned) to create it.
With tblSummary
.Columns(1).SetWidth ColumnWidth:=CentimetersToPoints(6), RulerStyle:=wdAdjustNone
.Columns(2).SetWidth ColumnWidth:=CentimetersToPoints(3), RulerStyle:=wdAdjustNone
.Rows.Alignment = wdAlignRowCenter
.Rows.SpaceBetweenColumns = CentimetersToPoints(0.38)
.Rows(1).Range.Font.Bold = wdToggle
.Rows(1).Range.Font.Name = "Arial"
.Rows(1).Range.Font.Size = 9
.Rows(1).Range.Font.Color = wdColorDarkRed
.Cell(1, 1).Range.Text = "Result"
.Cell(1, 2).Range.Text = "Count"
For j = 1 To UBound(gResSummArray, 2)
' Result text - need to left align
.Cell(j + 1, 1).Range.Text = gResSummArray(1, j)
' Count of results - need to right align
.Cell(j + 1, 2).Range.Text = gResSummArray(2, j)
.Rows(j + 1).Range.Font.Bold = False
.Rows(j + 1).Range.Font.Name = "Arial"
.Rows(j + 1).Range.Font.Size = 8
.Rows(j + 1).Range.Font.Color = wdColorBlack
Next j
.Sort ExcludeHeader:=True, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldAlphanumeric, _
casesensitive:=False, _
SortOrder:=wdSortOrderDescending
End With 'tblsummary
There is a header row.
Question
How can I do this without selecting the table ie. I am trying to avoid the Select.
Thanks