复制 PPT 中嵌入的 Excel OLE 对象
我正在尝试在 PPT 中使用 VBA 打开/编辑嵌入的 OLE Excel 对象,复制选定的单元格,然后将它们粘贴回同一张幻灯片中。这可能吗?我已经开始打开并编辑 ole 对象,但不知道如何复制已选择的单元格。它需要是已选择的单元格,因为数据引用不一致,因此不能使用静态单元格/工作表引用。到目前为止我的代码见下文。
Dim slide As Object
Dim shape As Object
For Each slide In ActivePresentation.Slides
For Each shape In slide.Shapes
If shape.Type = msoEmbeddedOLEObject Then
If InStr(shape.OLEFormat.ProgID, "Excel.Sheet") > 0 Then
shape.OLEFormat.DoVerb (1)
'''shape.OLEFormat.Object.Worksheets(1).Range("A1:F20").Copy
'''The above line works but I need the data reference to be dynamic.
End If
End If
Next
Next
I'm trying to use VBA in PPT to open/edit embedded OLE excel objects, copy the selected cells, and then paste them back into the same slide. Is this even possible? I've gotten to the point of opening and editing the ole object but can't figure out how to copy the already selected cells. It needs to be the already selected cells as the data references are inconsistent and thus, cannot use static cell/sheet references. See below for my code thus far.
Dim slide As Object
Dim shape As Object
For Each slide In ActivePresentation.Slides
For Each shape In slide.Shapes
If shape.Type = msoEmbeddedOLEObject Then
If InStr(shape.OLEFormat.ProgID, "Excel.Sheet") > 0 Then
shape.OLEFormat.DoVerb (1)
'''shape.OLEFormat.Object.Worksheets(1).Range("A1:F20").Copy
'''The above line works but I need the data reference to be dynamic.
End If
End If
Next
Next
Sample file:
https://github.com/semajkim/Extract_PPT_Data/blob/c64c2aebe13eaa81501c35d20a3553281fc187c0/Example_PPT.pptm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:无需打开工作簿。
Range.CurrentRegion
将为您提供动态范围。设置对
Microsoft Excel xx.x 对象库
的引用。这将允许您输入变量,从而启用智能感知。Note: There is no need to open the Workbooks.
Range.CurrentRegion
will give you the dynamic range.Setting a reference to the
Microsoft Excel xx.x Object Library
. This will allow you to type your variables, which enables Intellisense.