簡體   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