首页 > 解决方案 > 对象“形状”的“表格”方法失败 - PowerPoint

问题描述

我有一些代码从 excel 工作表中获取值并将它们粘贴到 powerpoint 中。然后我想格式化这些值:

    Dim shp as PowerPoint.Shape
    Dim tbl as Table
    Dim shp_count as Long

    sld.Shapes.PasteSpecial DataType:=ppPasteHTML, DisplayAsIcon:=msoFalse
    Application.CutCopyMode = False

    shp_count = sld.Shapes.Count

    Set shp = sld.Shapes(sld.Shapes.Count)
    shp.Name = key & "_Header"
    Set tbl = shp.Table
    With tbl.Cell(1, 1).Shape.TextFrame.TextRange
        .Font.Color = vbWhite
        .Characters(1, 11).Font.Bold = msoFalse
    End With

请注意,粘贴到 powerpoint 中的这个特殊形状只是一个单元格。

当我自己运行它时,它工作正常。但是,当另一个用户尝试在他们的机器上运行完全相同的代码时,我收到“对象‘形状’的‘表’方法失败”错误。知道为什么或更好的方法来做这件事吗?

标签: excelvbapowerpoint

解决方案


也许其他用户的电脑没有你的那么快,粘贴形状需要更多时间?尝试添加

  DoEvents

行前:

  Set tbl = shp.Table

推荐阅读