How to add pictures to Powerpoint Presentation Picture PlaceHolder?

☆樱花仙子☆ 提交于 2019-12-02 02:30:59

This is how you add pictures in currently open PPT Picture PlaceHolders using Excel.
We used Early Binding adding the Microsoft PowerPoint 14.0 Object Library reference.

Edit1: Adding DoEvents and some explanation

Sub ImportPictureInPlaceHolderFromExcel()

    Dim oPPt As PowerPoint.Application
    Dim oPPtSlide As PowerPoint.Slide
    Dim oPPtShp As PowerPoint.Shape

    '~~> Get hold of PPt instance meaning your currently open PPT presentation
    Set oPPt = GetObject(, "Powerpoint.Application")
    '~~> Reference the first slide which should contain picture placeholders
    Set oPPtSlide = oPPt.ActivePresentation.Slides(1)

    '~~> Now check each shape in slide
    For Each oPPtShp In oPPtSlide.Shapes
        '~~> You only need to work on Picture place holders
        If oPPtShp.PlaceholderFormat.Type = ppPlaceholderPicture Then
            With oPPtShp
                '~~> Now add the Picture
                '~~> For this example, picture path is in Cell A1
                oPPtSlide.Shapes.AddPicture Range("A1").Value, msoFalse, msoTrue, _
                                .Left, .Top, .Width, .Height
                '~~> Insert DoEvents here specially for big files, or network files
                '~~> DoEvents halts macro momentarily until the 
                '~~> system finishes what it's doing which is loading the picture file
                DoEvents
            End With
        End If
    Next

    Set oPPtSlide = Nothing
    Set oPPt = Nothing

End Sub

To sum-up:
1. We get hold of PPT application
2. We get hold of the slide and the shapes within the slide
3. Now we choose shapes which are ppPlaceholderPicture type only
4. We use the Shape Object's(ppPlaceholderPicture type) .Top, .Left, .Width and .Height property as argument for Shapes Collection's .AddPicture method.

And there you go, you've added a picture in your PPT Picture Placeholder.
Hope this is what you need.

John Wilson

While that looks like it works when you add an image to a slide with an empty picture or content placeholder it will always go into that placeholder and resize to fit.

You just need to add it like this:

osld.Shapes.AddPicture "Path", msoFalse, msoTrue, -1, -1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!