格式化PowerPoint 2013演示文稿中的每个表

时间:2016-04-18 16:06:20

标签: vba powerpoint-vba

为一个研究得很严重的问题道歉,但我对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函数,但我不知道如何正确地完成它。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

这一行:

FormatTheTable (shp.Table)

应该是:

FormatTheTable shp.Table

因为你没有调用Function类型的过程,它返回一个值,而Sub则没有。如果它是一个函数,那就没问题了:

myValue = FormatTheTable (shp.Table)

此线看起来有点奇怪:

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

因此,您要检查每个单元格是否存在文本,如果有文本,您是否尝试将文本转换为数字?那会引起错误。你想在那条线上试试什么?

相关问题