使用VBA更改图片 [英] Using VBA to change Picture

查看:841
本文介绍了使用VBA更改图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在Excel / Word / Powerpoint中右键单击一个形状时,我正在尝试使用VBA自动执行更改图片功能。

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?

推荐答案

据我所知,你不能改变图片的来源,您需要删除旧图片并插入新图片

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

这是一个开始

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

这篇关于使用VBA更改图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆