繁体   English   中英

Excel VBA:Excel范围到刚刚打开的PowerPoint

[英]Excel VBA: Excel range to just opened powerpoint

我已经有了从共享点打开特定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

您可以粘贴各种格式的数据。 这里有一篇很好的文章介绍了如何执行此操作,特别是有关可通过其粘贴数据的不同文件格式的内容。

该方法将其粘贴为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声明为“作为对象”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM