从 Excel VBA 编辑嵌入的 PowerPoint
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/124375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Editing Embedded PowerPoint from Excel VBA
提问by user4812
I have an embedded PowerPoint presentation in an Excel workbook. How can I edit this (open, copy slides, add data to slides, close) using VBA?
我在 Excel 工作簿中有一个嵌入的 PowerPoint 演示文稿。如何使用 VBA 编辑(打开、复制幻灯片、向幻灯片添加数据、关闭)?
回答by Joel Spolsky
1. Add a reference to the PowerPoint Object Model to your VBA application
1. 向 VBA 应用程序添加对 PowerPoint 对象模型的引用
From the VBA window, choose Tools | References
Look for Microsoft Powerpoint 12.0 Object Libraryand check it
在 VBA 窗口中,选择工具 | 参考
查找Microsoft Powerpoint 12.0 Object Library并检查它
2. Select and activate the PowerPoint presentation object
2.选择并激活PowerPoint演示文稿对象
ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlOpen
Note: this code assumes that the PowerPoint object is named Object 1(look in the top left corner to see what it's really named) and that it is on the active sheet.
注意:此代码假定 PowerPoint 对象被命名为对象 1(查看左上角以查看它的实际名称)并且它位于活动工作表上。
3. Get a reference to the Presentation object
3. 获取对 Presentation 对象的引用
Dim p As PowerPoint.Presentation
Set p = Selection.Object
4. Manipulate it
4. 操纵它
All the methods and properties of a presentation object are available to you. Here's an example of adding a slide:
您可以使用表示对象的所有方法和属性。这是添加幻灯片的示例:
p.Slides.Add 1, ppLayoutBlank
5. Deselect it
5.取消选择
The easiest way is just to select a cell.
最简单的方法就是选择一个单元格。
[a1].Select
Hope that helps!
希望有帮助!