2017-08-23 241 views
0

我已经有了从共享点打开特定的PowerPoint模板的代码。它已经运作。接下来我想要的是将不同工作表中的多个范围复制到新打开的PPT模板的第一张幻灯片中。顺便说一句,我的表是4,每个都有定义的范围来复制。我希望它粘贴在不同位置的同一张幻灯片上。Excel VBA:Excel范围到刚刚打开的Powerpoint

目前我唯一有此代码来打开PowerPoint演示模板:

Sub SPPPT() 

'*************Open template in sharepoint***************************** 

Dim FullTemplatePath As String 
Set PPApp = New PowerPoint.Application 
Dim OperationalKPI As Worksheet 
Set OperationalKPI = Sheets("OperationalKPI") 
Dim mySlide As Object 
Dim myShape As Object 
Dim PowerPointApp As Object 
Dim myPresentation As Object 

FullTemplatePath = "FilePathofPowerpointTemplate/PPT Template.pptx" 

'Open the PowerPoint template 
PPApp.Presentations.Open (FullTemplatePath) 

Dim OperationalKPI As Worksheet 
Set OperationalKPI = Sheets("OperationalKPI") 

Set rng = OperationalKPI.Range("KPIRange") 


End Sub 

回答

0

你可以粘贴各种格式的数据。关于如何做到这一点,有一篇很好的文章here,特别是关于可以通过粘贴数据的不同文件格式的位。

该方法将其粘贴为shape。下面是一些代码,我使用的是类似的文章:

'//Create and open powerpoint 
Dim ppt As PowerPoint.Application 
Set ppt = New PowerPoint.Application 

'//Set objects and open powerpoint 
Dim oPresentation As PowerPoint.Presentation 
Dim oTargetSlide As PowerPoint.Slide 
Dim oSelect As PowerPoint.ShapeRange 

Set oPresentation = ppt.Presentations.Open(sFileName) 

'//Copy the data 
ThisWorkbook.Sheets("Sheet1").Range("B4:B8").Select 
Selection.Copy 

'//Paste it into powerpoint 
With ppt 
    Set oTargetSlide = oPresentation.Slides(1) 
    oTargetSlide.Select 
    ppt.ActiveWindow.View.GotoSlide oTargetSlide.SlideIndex 
    Set oSelect = 
    oTargetSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject) 
    '//You can now change the .Left, .Top etc of oShape to place it where you want it. 
End With 

'//Get the save file name.... 
'... your code here 
oPresentation.SaveAs (SaveAsName) 
oPresentation.Close 
ppt.Quit 

我要么粘贴为ppPasteEnhancedMetafile,ppPastePNG或ppPasteOLEObject。

与我所做的一个关键区别是我使用的是PowerPoint 16对象库,而不是只声明我的PowerPoint“作为对象”。