通常我不是“请为我编写代码”的超级粉丝,但我对 Word 中的 VBA 做得还不够,我想自己学习一些。
这将使您大部分时间到达那里。
您目前没有提供足够的信息来让我保证该if
声明适用于整个文档,但您应该可以从这里开始。
Sub alignTableElementsRight()
Dim oTable As Table
Dim oRow As Row
Dim i As Integer
Dim dataTable As Boolean
For Each oTable In ActiveDocument.Tables
'this will be set once you are in the "table" part and
'not headings
dataTable = False
For Each oRow In oTable.Rows
'you will need custom logic here to determine what your if statement
'is to properly execute on the right row, this is going to depend based on your table
'format, etc. This checks if a leftmost column heading is "65 to 66"
If (InStr(oRow.Cells(1).Range.Text, "65 to 66") > 0) Then
dataTable = True
End If
'if you are in the datatable, move all values to align right in each row following
If (dataTable = True) Then
For i = 2 To oRow.Cells.Count
oRow.Cells(i).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
Next i
End If
Next oRow
Next oTable
End Sub