How to add a picture to a powerpoint slide from excel

时间:2021-06-30 13:04:36

I have set up a macro which saves some charts from an Excel spreadsheet as pictures (as part of a larger procedure), and need some code to paste these pictures, one per slide, into a slideshow.

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

Currently, I have successfully opened up a powerpoint presentation with 4 blank slides, and have not even managed to successfully import 1 picture.

目前,我已经成功开辟了4张空白幻灯片的powerpoint演示文稿,甚至还没有成功导入1张图片。

I have been using methods like shape.addpicture("C:\Users\restofpathname"), but have not managed to get them to work

我一直在使用像shape.addpicture(“C:\ Users \ restofpathname”)这样的方法,但还没有设法让它们工作

1 个解决方案

#1


0  

Here is the code which allowed me to put a picture in powerpoint, from excel. The code below works, and this link is also useful

这是允许我从excel中在powerpoint中放置图片的代码。以下代码有效,此链接也很有用

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

#1


0  

Here is the code which allowed me to put a picture in powerpoint, from excel. The code below works, and this link is also useful

这是允许我从excel中在powerpoint中放置图片的代码。以下代码有效,此链接也很有用

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