我编写了以下代码,用于将数据从Excel工作表复制并粘贴到Microsoft Excel 2016版本的Powerpoint幻灯片中。
但是,当我在较低的Microsoft Excel版本上运行此代码时,它在上述位置(代码的第二行)给出错误消息:-
Sub excltoppt()
Dim ppalApp As PowerPoint.Application
Dim ppalPres As PowerPoint.Presentation
Dim ppalSlide As PowerPoint.Slide
Set ppalApp = New PowerPoint.Application
ppalApp.Visible = True
ppalApp.Activate
Set ppalPres = ppalApp.Presentations.Open("C:\Desktop\Template.pptx")
ppalPres.Slides(6).Duplicate
Set ppalSlide = ppalPres.Slides(6)
'here it select data from specific excel sheet #6
Sheets("S06").Select
ActiveSheet.Range("D1:G21").Select
ActiveSheet.Shapes.SelectAll
Selection.Copy
'here it paste at the selected specific slide #6
ppalSlide.Shapes.PasteSpecial DataType:=wdPasteText
'here it select data from specific excel sheet #6
Sheets("S06").Select
ActiveSheet.Range("D14:H18").Select
Selection.Copy
'here it paste at the selected specific slide #6 - AND AT THIS PLACE I AM GETTING ERROR MESSAGE
ppalSlide.Shapes.PasteSpecial DataType:=wdPasteText
End Sub
它会从excel复制数据,将其粘贴到ppt,然后再次从excel复制数据,但这一次不会将其粘贴到ppt。