我想要一个循环遍历所有幻灯片的宏,并将表格中的文字更改为黑色。当我尝试下面的代码时,收到错误消息: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
答案 0 :(得分:1)
并非每个形状都有与之关联的表格。只需添加语句If oSh.HasTable Then...
它应该可以正常工作
应该放置此If
语句来封装所有Table调用,因此将其直接放在Set oTbl = oSh.Table
行之前