首页 > 解决方案 > 从 2016 到更低版本的 vba 兼容性

问题描述

我编写了以下代码,用于将 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。

标签: vba

解决方案


推荐阅读