【发布时间】:2020-08-23 13:51:43
【问题描述】:
我正在尝试使用 Excel VBA 将数据从 Excel 复制到 PowerPoint。
有时它会在运行过程中崩溃并停止。
Sub Test()
Set PowerPointApp = CreateObject("PowerPoint.Application")
Set ppApp = New powerpoint.Application
ppApp.Visible = True
DestinationPPT = "C:\Users\Saeed\Desktop\edit vba\test.pptx"
Set ppPres = PowerPointApp.Presentations.Open(DestinationPPT)
Sheets("Slide3").Activate
Sheets("Slide3").Range("A2").Select
Selection.Copy
ppApp.Activate
ppPres.Slides(3).Select
ppApp.Windows(1).View.Paste
Set shp = ppPres.Slides(3).Shapes(ppPres.Slides(3).Shapes.Count)
shp.Left = 17
shp.Top = 90
ppApp.Windows(1).Selection.Unselect
ppPres.SaveAs "C:\Users\Saeed\Desktop\edit vba\" & FileName, ppSaveAsPDF
ppPres.Close
ppApp.Quit
Set ppt = Nothing
我跳过了暗淡的部分和一些不重要的部分。
它崩溃了
ppApp.Windows(1).View.Paste
我不知道如何修复它,因为它有时运行完美。
我尝试使用On Error Goto,但没有任何改变。
【问题讨论】:
标签: excel vba powerpoint