代码更改所有幻灯片中的文本表颜色

时间:2016-07-06 14:13:53

标签: vba colors powerpoint powerpoint-vba

我想要一个循环遍历所有幻灯片的宏,并将表格中的文字更改为黑色。当我尝试下面的代码时,收到错误消息:Method 'Table' of 'Shape' failed

这是我的代码:

Sub TableAllBlack()

Dim lRaw As Integer
Dim lCol As Integer
Dim oTbl As Table
Dim osld As Slide
Dim oShp As Shape

With ActivePresentation
    For Each oSl In .Slides
        For Each oSh In oSl.Shapes
            Set oTbl = oSh.Table
                With oTbl
                    For lRow = 1 To .Rows.Count
                            For lCol = 1 To .Columns.Count
                                With .Cell(lRow, lCol).Shape
                                    If .HasTextFrame Then
                                        If .TextFrame.HasText Then
                                            TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
                                        End If
                                    End If
                                End With
                            Next
                    Next
                End With
            Next
        Next
End With


End Sub

1 个答案:

答案 0 :(得分:1)

并非每个形状都有与之关联的表格。只需添加语句If oSh.HasTable Then...它应该可以正常工作

应该放置此If语句来封装所有Table调用,因此将其直接放在Set oTbl = oSh.Table行之前