在Powerpoint演示文稿中以编程方式编辑文本,表和表属性



我必须写一个程序,从SharePoint读取一些数据,并将其写入PowerPoint演示文稿。演示文稿中有一些通配符,如##budget##,我必须用SharePoint中的值替换它们。我认为这可以通过搜索和替换到PowerPoint演示文稿中来完成。

但也有表格的背景必须是红色,绿色,黄色等,我不知道,有哪些选项可以识别特定的表格和受影响的单元格,哪一个是最好的方法。

这只适用于一个通配符;您可能希望将其更改为接受一个参数(您正在搜索的不同通配符文本字符串),或者调用另一个例程依次搜索每个通配符。但是这里是你如何在单元格中找到文本并根据需要给它上色的方法:

Dim oSl As Slide
Dim oSh As Shape
Dim oTbl As Table
Dim x As Long
Dim y As Long
For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes
        ' other code here to check for ## text in the shape
        If oSh.HasTable Then
            Set oTbl = oSh.Table
            With oTbl
                For x = 1 To .Rows.Count
                    For y = 1 To .Columns.Count
                        With .Cell(x, y)
                            If InStr(.Shape.TextFrame.TextRange.Text, "##budget##") > 0 Then
                                .Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
                            End If
                        End With
                    Next
                Next
            End With
        End If
    Next
Next

最新更新