VBA: Set border for Powerpoint table

和自甴很熟 提交于 2020-07-09 12:20:22

问题


I try to set a border to a existing powerpoint table. It runs through fine (and the row and column number is inserted in each cell as test data), but the border just does not appear. What am I doing wrong?

For i = 1 To myPresentation.Slides(w).Shapes(tableName).Table.Rows.Count
    For j = 1 To myPresentation.Slides(w).Shapes(tableName).Table.Columns.Count
        myPresentation.Slides(w).Shapes(tableName).Table.Cell(i, j).Shape.TextFrame.TextRange.Text = "R:" & i & " C:" & j
         With myPresentation.Slides(w).Shapes(tableName).Table.Cell(i, j)
            .Borders(ppBorderTop).DashStyle = msoLineSolid
            .Borders(ppBorderBottom).DashStyle = msoLineSolid
            .Borders(ppBorderLeft).DashStyle = msoLineSolid
            .Borders(ppBorderRight).DashStyle = msoLineSolid
            .Borders(ppBorderTop).ForeColor.RGB = RGB(255, 110, 0)
            .Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 110, 0)
            .Borders(ppBorderLeft).ForeColor.RGB = RGB(255, 110, 0)
            .Borders(ppBorderRight).ForeColor.RGB = RGB(255, 110, 0)
            .Borders(ppBorderBottom).Weight = 1
            .Borders(ppBorderTop).Weight = 1
            .Borders(ppBorderLeft).Weight = 1
            .Borders(ppBorderRight).Weight = 1
            .Borders(ppBorderBottom).Visible = msoTrue
            .Borders(ppBorderTop).Visible = msoTrue
            .Borders(ppBorderLeft).Visible = msoTrue
            .Borders(ppBorderRight).Visible = msoTrue
        End With
    Next j
Next i   

回答1:


Create a single slide presentation and add only two tables on it. Then run this code:

Public Sub TestMe()

    Dim myTable As Table
    Dim sh As Shape

    For Each sh In ActivePresentation.Slides(1).Shapes
        Set myTable = sh.Table
        myTable.Cell(1, 1).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 110, 0)
    Next sh

End Sub

It should work. From there try to build a bit further.



来源:https://stackoverflow.com/questions/51077220/vba-set-border-for-powerpoint-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!