Using VBA to change Picture

后端 未结 10 1005
庸人自扰
庸人自扰 2020-12-10 12:41

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, c

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 12:52

    'change picture without change image size
    Sub change_picture()
    strPic = "Picture 1"
    Set shp = Worksheets(1).Shapes(strPic)
    
    'Capture properties of exisitng picture such as location and size
    With shp
        t = .Top
        l = .Left
        h = .Height
        w = .Width
    End With
    
    Worksheets(1).Shapes(strPic).Delete
    
    Set shp = Worksheets(1).Shapes.AddPicture("d:\pic\1.png", msoFalse, msoTrue, l, t, w, h)
    shp.Name = strPic
    
    End Sub
    

提交回复
热议问题