简体   繁体   中英

Programatically edit Text, Tables and Tablesproperties in a Powerpoint presentation

I must write a program that read some data from SharePoint and write it into a PowerPoint presentation. There are some wildcards in the presentation, like ##budget## which I must replace with the values from SharePoint. This could be done by search and replace into the PowerPoint presentation, I think.

But there are also tables which background must be colored red, green, yellow etc. and I don't know, which options there are to identify the particular tables and the affected cells and which would be the best way to do that.

This would work for one wildcard; you'll want to change it to either take a parameter ( the different wildcard text strings you're searching for ) or to call another routine that searches for each wildcard in turn. But here's how you'd find text in a cell and color it as needed:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM