在 Powerpoint 中使用 VBA 调整 Excel 图表大小

Resizing Excel Chart Using VBA in Powerpoint

我知道之前有人问过这个问题,但由于我不是 VBA 专家,我似乎无法找到适用于我的特定情况的任何解决方案,所以我希望有人能提供帮助。

我有一些 VBA 代码可以从 Excel 中复制选择,打开一个基于模板的新 powerpoint 演示文稿,然后将数据粘贴到 powerpoint 的第二张幻灯片中。

我现在唯一想做的就是操纵图表的大小和位置。我需要在下面的代码中添加什么才能做到这一点?

   'Opens a new PowerPoint presentation based on template and pastes data into Slide 2 of Powerpoint from Excel

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", Untitled:=msoTrue)
    PPapp.Visible = True
    Set PPslide = PPpres.Slides(2)
    XLws.Range("A1:D16").Copy
    PPslide.Shapes.PasteSpecial DataType:=ppPasteHTML, Link:=msoFalse
    Application.CutCopyMode = False

定义一个 Shape 对象并尝试一下:

'Opens a new PowerPoint presentation based on template and pastes data into Slide 2 of Powerpoint from Excel

Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide, PPShape As Object
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", Untitled:=msoTrue)
PPapp.Visible = True
Set PPslide = PPpres.Slides(2)
XLws.Range("A1:D16").Copy
Set PPShape = PPslide.Shapes.PasteSpecial(DataType:=ppPasteHTML, Link:=msoFalse)
Application.CutCopyMode = False

With PPShape
    .Top = 10
    .Height = 100
    .Left = 10
    .Width = 100
End With