3

I have a Powerpoint presentation with a VBA script to update the images every week. Recently, I added 2 additional slides and scripting to update those images as well.

The new images do not update and do not throw an error. If I step through the procedure, it goes to the correct slide, selects the correct shape, but the

Call ppShp.Fill.UserPicture ("blah_blah.png")

does not replace the image.

If I copy the line to one of the slides where it does work, it does.

In the example below, the first one works, the second doesn't.

'FEOL *******************************************************************
    ActiveWindow.View.GotoSlide (15)
    Set ppShp = ActivePresentation.Slides(15).Shapes("FEOL")
    ppShp.Select
    Call ppShp.Fill.UserPicture("D:\MIT Trends\Images\Feol_Composite.png")

   'LICONSEM *******************************************************************
    ActiveWindow.View.GotoSlide (16)
    Set ppShp = ActivePresentation.Slides(16).Shapes("LICONSEM")
    ppShp.Select
    Call ppShp.Fill.UserPicture("D:\MIT Trends\Images\LICONSEM.png")

Again, I can see it go to the correct slide and select the correct shape (named in the "arrange" panel). It just doesn't fill. I tried changing to shape ID, but the results are the same. I know the shape name and image name are correct. I even tried cut/paste to be sure.

Using the image for the first section to fill in the second does not work. Using the image from the second section to fill in the first does. I feel like I must be missing something obvious.

  • Fixed but not explained. I duplicated slide 15 to create a new slide 16. I copied the shape name into the new slide 16 replacing the old shape name. Now it works. I do not understand the difference between the two. – user1330705 Aug 01 '16 at 19:32
  • This shouldn't matter, but have you tried doing it without `Call` (you don't need to use this keyword to invoke a method of an object. Or you could try deleting the current shape and adding a new shape with picture as suggested in one of the answers [here](http://stackoverflow.com/questions/10169011/using-vba-to-change-picture) – David Zemens Aug 01 '16 at 19:54

2 Answers2

0

Please find my code in attached image. First u need to create shape in PPT and then run code.enter image description here

Tarun Reddy
  • 2,123
  • 2
  • 11
  • 6
0
Sub imagerep()
Dim EptApp As Object
Dim Ppthoc As Object
Set Ppthpp = CreateObject ("PowerPoint.Application”)
Set PptDoc = PptApp.Presentations.Open ("C:\Users\TarunReddyNuthula\Desktop\gprop2.pprx”, msoCTrue)

EptDoc.Slides (1) .Shapes ("newimage”) .Fill.UserPicture ("
£nd Sub

Users\TarunReddyNuthula\Desktop\zoomcarAl . Jpg

James Risner
  • 5,451
  • 11
  • 25
  • 47
  • I moved the code into formatting, but is this OCR? Because End is the "£" then "nd"? – James Risner Mar 05 '23 at 22:06
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 10 '23 at 11:41