Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VBA to change Picture

I am trying to use VBA to automate the Change Picture function when you right click a Shape in Excel/Word/Powerpoint.

However, I am not able to find any reference, can you assist?

like image 385
PlayKid Avatar asked Apr 16 '12 05:04

PlayKid


1 Answers

So far as I know you can't change the source of a picture, you need to delete the old one and insert a new one

Here's a start

strPic ="Picture Name"
Set shp = ws.Shapes(strPic)

'Capture properties of exisitng picture such as location and size
With shp
    t = .Top
    l = .Left
    h = .Height
    w = .Width
End With

ws.Shapes(strPic).Delete

Set shp = ws.Shapes.AddPicture("Y:\our\Picture\Path\And\File.Name", msoFalse, msoTrue, l, t, w, h)
shp.Name = strPic
shp.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
shp.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue
like image 70
chris neilsen Avatar answered Sep 19 '22 18:09

chris neilsen