【问题标题】:Excel to update PowerPoint PresentationExcel 更新 PowerPoint 演示文稿
【发布时间】:2018-11-22 14:08:01
【问题描述】:

我有一个演示文稿,我必须每周更新它。我更新的信息是我从 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.: 对不起我的英语不好

【问题讨论】:

  • 我建议Automatic Updating of Excel Tables in PowerPoint Slides。因此您不必手动更新您的演示文稿。
  • 这是一个很好的解决方案,但我需要演示文稿没有文件链接...它在公司和图像中传播,我认为这是保存信息的唯一方法。
  • @RodrigoKroehn 我认为如果源文件的链接不再可用(您可以测试它),它只会保留旧值,如果链接源可用则更新。所以也许值得再看一下。

标签: excel vba powerpoint


【解决方案1】:

此示例(基于您的代码)可能会为您指明正确的方向。您需要知道 powerpoint 形状名称(您可以通过 VBA 或功能区 Home-Select-Selection 窗格获得。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2017-05-30
    • 2012-01-09
    • 1970-01-01
    • 2016-05-10
    • 2020-03-05
    • 2014-01-26
    相关资源
    最近更新 更多