如何将图片添加到来自 excel 的 powerpoint 幻灯片

How to add a picture to a powerpoint slide from excel

我已经设置了一个宏,可以将 Excel 电子表格中的一些图表保存为图片(作为更大过程的一部分),并且需要一些代码来将这些图片(每张幻灯片一张)粘贴到幻灯片中.

目前,我已经成功打开了4张空白幻灯片的powerpoint演示文稿,连一张图片都没有成功导入。

我一直在使用 shape.addpicture("C:\Users\restofpathname") 之类的方法,但未能使它们发挥作用

这是允许我在 powerpoint 中放图片的代码,来自 excel。下面的代码有效,this link 也很有用

Dim applPP As PowerPoint.Application, prsntPP As PowerPoint.Presentation, TitlePage As PowerPoint.Slide

    Set applPP = New PowerPoint.Application
    applPP.Visible = True
    Set prsntPP = applPP.Presentations.Add
    Set TitlePage = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitle)
    prsntPP.SaveAs ("C:\Users\...")

        Dim oSlide As PowerPoint.Slide
        Dim oPicture As PowerPoint.Shape

        Set oSlide = prsntPP.Slides(1)

        Set oPicture = oSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", _
            msoFalse, msoTrue, 1, 2, 3, 4)

        oPicture.ScaleHeight 0.9, msoTrue
        oPicture.ScaleWidth 0.9, msoTrue

        With prsntPP.PageSetup
            oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
            oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
        End With