![](/img/trans.png)
[英]Open a Powerpoint Presentation and update the Excel links in VBA
[英]Excel to update PowerPoint Presentation
我有一個演示文稿,我必須每周更新。 我更新的信息是我從 Excel 數據透視表生成的一堆圖像(從 Excel 復制並直接粘貼到 PowerPoint 上)。 今天我可以這樣做:
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set PPTPrez =
objPPT.Presentations.Open("\\network_folder\presentation.pptm")
Set pSlide = PPTPrez.Slides(2)
If pSlide.Shapes.Count <> 0 Then
ActiveWorkbook.Sheets("Pivot1").Range("A8:Z18").CopyPicture
pSlide.Shapes.Paste
EndIf
它工作完美......但我需要更多的控制和精確度......我需要選擇幻燈片上的當前圖像,將其刪除並將新圖像粘貼到同一位置......有些幻燈片有3張或更多圖片...我不知道如何正確地告訴 VBA 什么圖像是什么,並為該圖像選擇具有正確信息的數據透視表...我什至不知道這是否可能......但是另一個我試過的解決方案是如何在幻燈片上指定圖片的位置和尺寸...我可以在更新之前,刪除所有圖片...在這種情況下,如何指定尺寸和定位?
謝謝!!!
Ps.: 對不起我的英語不好
此示例(基於您的代碼)可能會為您指明正確的方向。 您需要知道 powerpoint 形狀名稱(您可以通過 VBA 或功能區 Home-Select-Selection Pane 獲得。
Option Explicit
Public Sub UpdateShapes()
Dim vPowerPoint As PowerPoint.Application
Dim vPresentation As Presentation
Dim vSlide As Slide
Dim vShapeName As String
Dim vShape, vNewShape
Set vPowerPoint = New PowerPoint.Application
vPowerPoint.Visible = True
' Open the powerpoint presentation
Set vPresentation = vPowerPoint.Presentations.Open("\\network_folder\presentation.pptm")
' Set slide to be worked on
Set vSlide = vPresentation.Slides(2)
' Set shape to (for this example) "Picture 3"
vShapeName = "Picture 3"
Set vShape = vSlide.Shapes(vShapeName)
' Copy and paste new shape (picture) of range specified
ThisWorkbook.Sheets("Sheet1").Range("A6:B9").CopyPicture
Set vNewShape = vSlide.Shapes.Paste
' Align size and position of new shape to that of old shape
With vNewShape
.Width = vShape.Width
.Height = vShape.Height
.Left = vShape.Left
.Top = vShape.Top
End With
' Delete original shape, rename new shape to original so code works next replace cycle
vSlide.Shapes(vShapeName).Delete
vNewShape.Name = vShapeName
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.