none
Replacing (changing) the pictures in PowerPoint presentation RRS feed

  • Question

  • I am trying to write a small program to replace pictures in PowerPoint
    presentation...

    To find the pictures, I check Shape Type (Shape.Type = msoPicture)...

    But the problem is: how can I change the picture after this step? What is the method I should use to load the new picture from file to the
    Shape?

    Best regards and have a nice day,
    Hani
    Friday, April 13, 2007 5:15 PM

Answers

  • Hi Hani,

     

    you can try something like this:

     

    Sub teste()

    Dim Pres As Presentation
    Dim Sld As Slide
    Dim shp As Shape
    Dim l As Single
    Dim t As Single
    Dim h As Single
    Dim w As Single
    Dim strName As String

    Set Pres = ActivePresentation

    Set Sld = Pres.Slides(1)

    For Each shp In Sld.Shapes
        If shp.Type = msoPicture Then
            l = shp.Left
            t = shp.Top
            h = shp.Height
            w = shp.Width
            strName = shp.Name
            shp.Delete
            Set shp = Sld.Shapes.AddPicture("C:\Users\Luiz\Pictures\Caio\DSC01531.JPG", _
            msoFalse, msoCTrue, l, t, w, h)
            shp.Name = strName
        End If
    Next shp

    End Sub

    Saturday, April 14, 2007 3:15 AM

All replies

  • Hi Hani,

     

    you can try something like this:

     

    Sub teste()

    Dim Pres As Presentation
    Dim Sld As Slide
    Dim shp As Shape
    Dim l As Single
    Dim t As Single
    Dim h As Single
    Dim w As Single
    Dim strName As String

    Set Pres = ActivePresentation

    Set Sld = Pres.Slides(1)

    For Each shp In Sld.Shapes
        If shp.Type = msoPicture Then
            l = shp.Left
            t = shp.Top
            h = shp.Height
            w = shp.Width
            strName = shp.Name
            shp.Delete
            Set shp = Sld.Shapes.AddPicture("C:\Users\Luiz\Pictures\Caio\DSC01531.JPG", _
            msoFalse, msoCTrue, l, t, w, h)
            shp.Name = strName
        End If
    Next shp

    End Sub

    Saturday, April 14, 2007 3:15 AM
  • Thanks Luiz,

    I can imagine that, without a directly method to replace the picture… it will be very complicated; especially if the old picture is a member in a group, has costume animation, and transparency, Z order...


    Thanks again Luiz and have a nice day,
    Hani


    Saturday, April 14, 2007 5:30 AM
  • Hi

    1. insert shape (not picture ) on slide

    2. create new macro and use this code activepresentation.slides(n).shapes(n).userpicture "c:\picname.jpg"

    3.run macro

    Sunday, August 12, 2012 8:54 PM