[英]Paste a range from Excel into certain slide of Powerpoint Template using VBA
我花了好幾個小時查看針對我的問題的各種建議解決方案,但找不到任何似乎可以完成工作的東西,或者更有可能的是,我對 VBA 的掌握是了解我理解在線解決方案的能力。 因此,我希望你們中的一位能幫助我解決問題。
我打開了一個 Excel 工作表,其中包含少量數據(標題和數字等)
我想復制此范圍並將其粘貼(不是作為圖片,如果需要,我希望能夠在 powerpoint 中對其進行格式化)在我已經創建的 Powerpoint 模板中的特定幻燈片(幻燈片 2)上。
我的 VBA 使用以下代碼正確打開基於模板的新演示文稿:
'Opens a PowerPoint Document from Excel
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'Change the directory path and file name to the location
'of your document
objPPT.Presentations.Open "C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm", Untitled:=msoTrue
但是,這就是我卡住的地方 - 我不知道如何在演示文稿打開后將 Excel 表格數據粘貼到正確的幻燈片中。 我的數據在 A1:D16 范圍內
非常感謝你提前
試試這個。 我已將 Excel 工作表分配給一個變量 ( XLws
),並將 PowerPoint 幻燈片分配給另一個變量 ( PPslide
)。 您可以在它們之間復制/粘貼對象。
順便說一句,您需要啟用 PowerPoint 庫。 如果不這樣做,請在 VBA 項目中轉到Tools -> References -> Microsoft PowerPoint 15.0 Object Library 。
Sub PPcopy()
Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide
Dim XLws As Worksheet
Set XLws = ActiveSheet
Set PPapp = New PowerPoint.Application
Set PPpres = PPapp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm")
PPapp.Visible = True
Set PPslide = PPpres.Slides(2)
XLws.Range("A1:D16").Copy
PPslide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
Application.CutCopyMode = False
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.