PHP Code:
[b]Yes, there is a way to automatically align a table to the center using VBA in Word.[/b] Here's how you can modify your existing code to achieve this:
[list=1][*] After inserting the table, select the entire table using the following code:
[code]Selection.Tables(1).Select[/code]
[*] Set the alignment of the selected table to center using the following code:
[code]Selection.Tables(1).Rows.Alignment = wdAlignRowCenter[/code]
[*] Deselect the table using the following code:
[code]Selection.Collapse Direction:=wdCollapseEnd[/code][/list]
Here's the modified code with the above changes:
[code]
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=myRow, NumColumns:=myCol, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
If .Style "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Select
.Rows.Alignment = wdAlignRowCenter
End With
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.TypeText Text:="Figure 1. Testing"
Selection.MoveLeft Unit:=wdCharacter, Count:=10
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
[/code]