【问题标题】:VBA: Set border for Powerpoint tableVBA:为 Powerpoint 表格设置边框
【发布时间】:2018-06-28 16:56:53
【问题描述】:

我尝试为现有的 powerpoint 表格设置边框。它运行良好(并且行号和列号作为测试数据插入每个单元格中),但边框没有出现。我究竟做错了什么?

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   

【问题讨论】:

    标签: vba excel powerpoint


    【解决方案1】:

    创建一个幻灯片演示文稿并在其上仅添加两个表格。然后运行这段代码:

    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
    

    它应该工作。 从那里尝试进一步构建。

    【讨论】:

    • 谢谢,效果很好。我意识到问题在于,我使用的是 Excel 宏,因为我使用 Excel 中的数据来填充现有的 powerpoint 表。知道如何将您的代码传输到 Excel 宏吗?虽然此代码在 Powerpoint 中运行良好: ActivePresentation.Slides(1).Shapes("Table 6").Table.Cell(1, 2).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 110, 0)
    • @Daniel - 不客气 :) 您可以考虑将此答案标记为已接受 - stackoverflow.com/help/someone-answers
    • 呃,我刚刚编辑了我上面的评论,对不起。知道如何使宏在 excel 中工作吗?
    • @Daniel - 将 ppBorderTop 替换为 1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多