Excel VBA:Excel范围刚刚打开的powerpoint

时间:2017-08-23 03:41:27

标签: excel-vba powerpoint vba excel

我已经有了从sharepoint打开特定powerpoint模板的代码。它已经有效了。接下来我想要的是将不同工作表的多个范围复制到新打开的powerpoint模板的第一张幻灯片中。顺便说一句,我的床单是4,每个都有定义的范围要复制。我希望它粘贴在不同位置的同一张幻灯片上。

目前我只有这段代码才能打开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

1 个答案:

答案 0 :(得分: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声明为“对象”。