PDA

View Full Version : [SOLVED:] Rename picture PowerPoint



NaB
08-04-2021, 03:02 PM
Good night, I'm new here...
I have a doubt about vba PowerPoint. I have written a line of code that opens a picture obtained from my hard drive.

Sub OpenPicture()
Set MyDocument=ActivePresentation.Slides(1)
MyDocument.Shapes.AddPicture Filename:="D:\User\Desktop\Prueba.jpg", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=100, Top:=100, Width:=270, Height:=270

End Sub

The code runs ok but the system gives a random name for the picture and ]I don't know how to rename it so I can manipulate it later.

PS: Apologies for my English,

Thank you very much for your help.

Paul_Hossler
08-04-2021, 04:22 PM
Option Explicit


Sub OpenPicture()
Dim oSlide As Slide
Dim oPicture As Shape

Set oSlide = ActivePresentation.Slides(1)
Set oPicture = oSlide.Shapes.AddPicture(FileName:="D:\User\Desktop\Prueba.jpg", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=100, Top:=100, Width:=270, Height:=270)


oPicture.Name = "My Inserted Picture"
End Sub


28817

NaB
08-06-2021, 01:39 PM
It's working!
Thank you Paul!:clap: