使用 Powerpoint VBA 更改每个 table 中 1 个单元格的颜色

Change the color of 1 cell in every table with Powerpoint VBA

我正在尝试使用 Powerpoint VBA

更改每个 table 中 1 个单元格的颜色

现在我的代码为每个 table 的第一行中的每个单元格着色。如何让它只为第 1 行第 2 列的单元格着色?

Sub RecolorTableHeader()
    Dim oSl As Slide
    Dim oSh As Shape
    Dim x As Long

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If oSh.HasTable Then
                With oSh.Table
                    For x = 1 To .Columns.Count
                        .Cell(1, x).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
                    Next
                End With
            End If
        Next
    Next
End Sub

从上面的评论来看,您似乎很接近,但您的某些表格在位置 1,2 处没有单元格,这导致了您的错误。

考虑尝试以下代码段:

Sub RecolorTableHeader()
    Dim oSl As Slide, _
        oSh As Shape

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If oSh.HasTable Then
                With oSh.Table
                    If .Columns.Count >= 2 Then
                        Let .Cell(1, 2).Shape.Fill.ForeColor.RGB = rgbRed
                    End If
                End With
            End If
    Next oSh, oSl
End Sub