首页 文章

如何在PPT VBA中更改表头颜色

提问于
浏览
0

我有一个100幻灯片的PowerPoint演示文稿与大量的表,并希望使用VBA代码来更改每个表上的 Headers 的颜色 . 模板的默认颜色输入具有以下格式的表格, Headers 颜色为RGB(79,129,189):
enter image description here

我需要将 Headers 颜色更改为更深的蓝色RGB(0,56,104) . 见下面的例子:
enter image description here

以前使用下面的代码来改变演示文稿中的形状颜色,所以想知道这个新任务是否有类似的方法 . 在此先感谢您的帮助 .

`Sub ChangeShapeColor()

Dim shp As Shape
Dim sld As Slide

For Each shp In ActivePresentation.Slides

    ' Look at each shape on each slide:
    For Each shp In sld.Shapes

        If shp.Fill.ForeColor.RGB = RGB(79, 129, 189) Then


        shp.Fill.ForeColor.RGB = RGB(0, 56, 104)

        End If

    Next shp

Next sld

结束Sub`

1 回答

  • 0

    这会将演示文稿中每个表的第一行的颜色更改为红色 . 您可以根据需要调整颜色,如果只想更改 Headers 为特定颜色的表,则添加If / Then .

    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
    

相关问题