【发布时间】:2020-06-14 23:47:07
【问题描述】:
我正在尝试根据边框是否为某种颜色来更改每张幻灯片上表格边框的颜色。但是,我不断收到运行时错误 91 - 对象变量或未设置块变量。知道我哪里出错了吗?
Dim myTable As Table
Dim sh As Shape
Dim sl As Slide
Dim iRow As Integer
Dim iCol As Integer
For Each sl In ActivePresentation.Slides
For Each sh In sl.Shapes
If sh.HasTable Then Set myTable = sh.Table
For iRow = 1 To myTable.Rows.count
For iCol = 1 To myTable.Columns.count
If myTable.Cell(iRow, iCol).Borders(ppBorderTop).ForeColor.RGB = RGB(0, 0, 0) Then myTable.Cell(iRow, iCol).Borders(ppBorderTop).ForeColor.RGB = RGB(100, 0, 0)
If myTable.Cell(iRow, iCol).Borders(ppBorderBottom).ForeColor.RGB = RGB(0, 0, 0) Then myTable.Cell(iRow, iCol).Borders(ppBorderBottom).ForeColor.RGB = RGB(100, 0, 0)
If myTable.Cell(iRow, iCol).Borders(ppBorderLeft).ForeColor.RGB = RGB(0, 0, 0) Then myTable.Cell(iRow, iCol).Borders(ppBorderLeft).ForeColor.RGB = RGB(100, 0, 0)
If myTable.Cell(iRow, iCol).Borders(ppBorderRight).ForeColor.RGB = RGB(0, 0, 0) Then myTable.Cell(iRow, iCol).Borders(ppBorderRight).ForeColor.RGB = RGB(100, 0, 0)
Next iCol
Next iRow
Next sh
Next sl
【问题讨论】:
-
你看过这个答案VBA: Set border for Powerpoint table 吗?
-
@PeterT 谢谢。我已经创建了一些代码,但是我得到了运行时错误 91(更新的 Q)有什么想法吗?
-
您在表格上的整个双循环需要在您的
If sh.HasTable Then语句中。您可能会在没有表格的幻灯片上遇到错误。 -
^ 需要使用 If...Then...End If 的多行语法。
-
有了这样的所有功能,试着录制一个宏,看看它是如何设置属性的,然后将它应用到你自己的代码中。
标签: vba powerpoint