Insert Image in a PowerPoint Presentation Using VBA

In this article I will explain how you can insert an image into a PowerPoint presentation using VBA.

Sub main()
Dim objPresentaion As Presentation
Dim objSlide As Slide
Dim objImageBox As Shape

Set objPresentaion = ActivePresentation
Set objSlide = objPresentaion.Slides.Item(2)

Set objImageBox = objSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg", msoCTrue, msoCTrue, 100, 100)
End Sub

The code above inserts the image located in the path “C:\Users\Public\Pictures\Sample Pictures\Desert.jpg” onto slide number “2”. For more information about the parameters to the function please see the link below:

Case 1: Inserting image into a slide without an image holder:

Consider the slide below:
Case 1
As you can see the slide has 2 shapes which are both textboxes. The code above will yield the following result:
Case 1 Result
The 4th and 5th parameters are the distance from the left and top sides of the screen respectively.
Note: By supplying the optional 6th and 7th parameters you can set the width and height of the inserted image respectively.

Case 2: Inserting image into a slide with a single image holder:

Consider the slide below that has 1 image holder:
Case 2
By calling the function, the image will be inserted inside the image holder and it will be resized to fit the image holder.
Case 2 Result
Note: The 4th, 5th, 6th and 7th parameters to the AddPicture function will have no effects in this case. You can modify the position and size of the image by using the code below:

objSlide.Shapes.Item(2).Top = 300
objSlide.Shapes.Item(2).Left = 500
objSlide.Shapes.Item(2).Width = 300
objSlide.Shapes.Item(2).Height = 100

Case 3: Inserting image into a slide with more than one image holder:

In this case every time you call the function, the image will be inserted in one of the image holders:
Case 3 Result

2 thoughts on “Insert Image in a PowerPoint Presentation Using VBA”

  1. Mathi says:


    I am trying to use the same function as in the SmartArt Hierarchy org chart where when I click on the image it will prompt me to insert image. I am doing my own org chart with circles to insert images of my staff so they can just click and insert their pictures. Really need help. I believe it involves macro with action box over mouse click.

  2. tarun says:

    Sub imagerep()
    Dim PptApp As Object
    Dim PptDoc As Object
    Set PptApp = CreateObject(“PowerPoint.Application”)
    Set PptDoc = PptApp.Presentations.Open(“C:\Users\TarunReddyNuthula\Desktop\gprop2.pptx”, msoCTrue)
    PptDoc.Slides(1).Shapes(“newimage”).Fill.UserPicture (“C:\Users\TarunReddyNuthula\Desktop\zoomcarAI.jpg”)
    End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *