通常我不是一個「請爲我寫代碼」的巨大粉絲,但我沒有做足夠的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
是你的表** **所有格式這樣嗎?或者他們會有各種格式,列,行等? – enderland
行數和列數會有所不同,但通用格式是相同的。正確的方向任何一點將不勝感激。謝謝! –