【发布时间】:2021-02-10 01:13:36
【问题描述】:
我有包含多个表格的 PowerPoint 文件,我正在尝试编写一个 excel vba 代码来打开文件,遍历幻灯片和形状,然后将表格传输到 excel 中。为此,我只想知道如何循环播放幻灯片并将任何和所有形状/表格传输到 Excel。
这是我当前的代码:
Sub PP_Test()
Dim s As Slide
Dim sh As Shape
Dim wbk As Workbook
Dim wsh As Worksheet
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
Dim file As String
file = "C:\Example.pptx"
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Open(file)
Set wbk = Workbooks("Test.xlsm")
'Loop through the slides and loop through the shapes to find all the Tables. Copy the table, and paste them in Excel
For Each s In ActivePresentation.Slides
For Each sh In s.Shapes
'Create a new sheet in Excel
Set wsh = wbk.Worksheets.Add(After:=wbk2.Worksheets(wbk2.Worksheets.Count))
' Copy/paste the shape/table
sh.Copy
wsh2.Paste
Next sh
Next s
End Sub
我目前在“For Each s In Active Presentation.Slides”行中遇到以下运行时错误: 运行时错误“429”:ActiveX 组件无法创建对象
我四处寻找示例,但我只能找到如何将表格从 excel 传输到 PowerPoint 的示例,反之则找不到。
【问题讨论】: