我有一个包含多个表格的 Word 文档。我希望能够选择表格(或表格中的单元格)并让表格中的每一行都以交替颜色着色。到目前为止,我已经创建了以下代码:
Sub ColorTable()
'
' ColorTable Macro
' Alternately colors cells.
'
Selection.Collapse Direction:=wdCollapseStart
If Not Selection.Information(wdWithInTable) Then
MsgBox "Can only run this within a table"
Exit Sub
End If
Dim RowCount, i, count, ColCount As Integer
RowCount = ActiveDocument.Tables(1).Rows.count
i = 0
ColCount = ActiveDocument.Tables(1).Columns.count
For i = 1 To RowCount
For count = 1 To ColCount
Selection.Shading.BackgroundPatternColor = RGB(184, 204, 228)
'light
Selection.MoveRight Unit:=wdCharacter, count:=1
Next count
Selection.MoveDown Unit:=wdLine, count:=1
For count = 1 To ColCount
Selection.Shading.BackgroundPatternColor = RGB(219, 229, 241)
'dark
Selection.MoveRight Unit:=wdCharacter, count:=1
Next count
Next i
End Sub
宏运行没有错误,但以对角线模式更改单元格颜色。我猜问题出在我的 for 循环中。