2017-08-23 239 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「作爲對象」。