使用VBA将Excel中的范围粘贴到Powerpoint模板的某个幻灯片中

我已经花了好几个小时来看看我的问题的各种build议的解决scheme,但找不到任何似乎做这项工作的东西,或者更可能的是,我对VBA的理解是理解我理解在线解决scheme的能力。 因此,我希望你们中的一个友善的人可以帮我解决问题。

我有一个Excel工作表打开包含less量的数据(标题和数字等)

我想复制这个范围,并在我已经创build的Powerpoint模板中粘贴(不是照片,我希望能够在PowerPoint中格式化,如果有必要)在特定的幻灯片(幻灯片2)。

我的VBA使用下面的代码正确打开了基于模板的新演示文稿:

'Opens a PowerPoint Document from Excel Dim objPPT As Object Set objPPT = CreateObject("PowerPoint.Application") objPPT.Visible = True 'Change the directory path and file name to the location 'of your document objPPT.Presentations.Open "C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm", Untitled:=msoTrue 

但是,这是我卡住的地方 – 我不知道如何将Excel表格数据粘贴到正确的幻灯片,一旦演示文稿打开。 我的数据在范围A1:D16

非常感谢你提前

试试这个。 我已经将Excel工作表分配给一个variables( XLws ),并将PowerPoint幻灯片分配给另一个variables( PPslide )。 您可以在它们之间复制/粘贴对象。

顺便说一句,你需要启用PowerPoint库。 如果你不这样做,在你的VBA项目中,进入工具 – >参考 – > Microsoft PowerPoint 15.0对象库

 Sub PPcopy() Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide Dim XLws As Worksheet Set XLws = ActiveSheet Set PPapp = New PowerPoint.Application Set PPpres = PPapp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm") PPapp.Visible = True Set PPslide = PPpres.Slides(2) XLws.Range("A1:D16").Copy PPslide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse Application.CutCopyMode = False End Sub