首页 > 解决方案 > 更新PowerPoint幻灯片中的许多形状之一

问题描述

我正在尝试使用 excel 表中的 vba 复制范围来更新 powerpoint 幻灯片中的许多形状之一。虽然我可以选择形状,但我无法粘贴到其中。下面的代码执行正确。

PowerPointApp.ActivePresentation.Slides(2).Select
PowerPointApp.ActivePresentation.Slides(2).Shapes("Table 4").Select

但是下面的代码给出了“对象不支持这个属性/方法”错误。

PowerPointApp.ActivePresentation.Slides(2).Shapes("Table 4").Paste

表 4 已经存在于幻灯片中,我需要用新数据更新它,所以我需要删除表 4 然后重新生成它吗?

标签: excelvbapowerpoint

解决方案


表 4 已经存在于幻灯片中,我需要用新数据更新它,所以我需要删除表 4 然后重新生成它吗?

要么删除并重新生成,要么用新数据替换现有表中的数据。

如果您创建一个新表,您可能需要编写大量代码来从原始表中提取 z 顺序和格式并将其应用于新表。更改现有表中的数据通常会简单得多。

顺便说一下,这部分:

PowerPointApp.ActivePresentation.Slides(2).Select
PowerPointApp.ActivePresentation.Slides(2).Shapes("Table 4").Select

不是最好的方法。如果不是绝对必要的话,永远不要选择任何东西,在这种情况下它不是。

反而:

With PowerPointApp.ActivePresentation.Slides(2).Shapes("Table 4")
   ' do stuff
End With

或者

Dim oTbl as Object
Set oTbl = PowerPointApp.ActivePresentation.Slides(2).Shapes("Table 4")
With oTbl
   ' do stuff
End With

推荐阅读