Sub 交替填充表格行背景色()
Dim sh As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
x = 1
'分别确定标题行色、奇数行颜色和偶数行颜色
biaoti = RGB(217, 217, 217)
jishu = RGB(0, 0, 0)
oushu = RGB(12, 17, 127)
With ActivePresentation.Slides(1)
For sh = 1 To .Shapes.Count
If .Shapes(sh).HasTable Then
With ActivePresentation.Slides(1).Shapes(sh).Table
'确定表格行列数
iCol = .Columns.Count
iRow = .Rows.Count
'令第一个单元格的填充色为标题色
With .Cell(1, 1)
.Shape.Fill.ForeColor.RGB = biaoti
End With
'填充标题行颜色,判断下一行第一个单元格的填充颜色是否与标题填充色一致,如一致换到下一行
While .Cell(x, 1).Shape.Fill.ForeColor.RGB = biaoti
For m = 1 To iCol
.Cell(x, m).Shape.Fill.ForeColor.RGB = biaoti
Next
x = x + 1
Wend
'对标题行之外的表格范围,按行交替填充单元格颜色
For i = x To iCol
If (i - x + 1) Mod 2 = 1 Then
tianchong = jishu
Else
tianchong = oushu
End If
'开始填充当前行单元格
For j = 1 To iRow
Set oCell = .Cell(i, j)
With oCell
.Shape.Fill.ForeColor.RGB = tianchong
End With
Next j
'当前行填充完毕
Next i
End With
End If
Next
End With
End Sub