在 PowerPoint 2013 演示文稿中格式化每个 table

Format every table in PowerPoint 2013 presentation

对于一个研究得不好的问题表示歉意,但我对 VBA 的一般知识知之甚少,尤其是对 PowerPoint 中的 VBA 知之甚少,并且我对可能是基本概念的内容感到困惑。

我正在尝试有条件地格式化我演示文稿中的所有表格,并且正在调整 this code from a SuperUser answer 以解决我的问题。

我想出了这个基本宏:

Sub FormatTheTable(oTbl As Table)
    Dim x As Long
    Dim y As Long

    With oTbl
    For x = 1 To .Rows.Count
    For y = 1 To .Columns.Count
        If .Cell(x, y).Shape.TextFrame.HasText Then
            If CDbl(.Cell(x, y).Shape.TextFrame.TextRange.Text) > 0 Then
                .Cell(x, y).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
            End If
        End If
    Next    ' Column
    Next    ' Row
    End With    ' otbl
End Sub

Sub DoIT()

    Dim sld As Slide
    Dim shp As Shape

    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
            If shp.HasTable Then
                FormatTheTable (shp.Table)
            End If
        Next shp
    Next sld

End Sub

我认为我没有正确调用 FormatTheTable 函数,但我不知道如何正确完成。非常感谢任何帮助!

这一行:

FormatTheTable (shp.Table)

应该是:

FormatTheTable shp.Table

因为您调用的不是 Function 类型的过程,returns 是一个值,而是一个没有值的 Sub。如果它是一个函数,这就可以了:

myValue = FormatTheTable (shp.Table)

另外这一行看起来有点奇怪:

If CDbl(.Cell(x, y).Shape.TextFrame.TextRange.Text) > 0 Then

因此,您正在检查每个单元格中是否存在文本,如果有文本,您是否正在尝试将文本转换为数字?那会引发错误。你想在那行测试什么?