首页 > 解决方案 > Visio VBA 更改图片

问题描述

试图在 Visio 组织结构图中更改此人的图片。我可以通过手动单击“更改图片”并浏览来更改它,但是 ChangePicture 方法给了我一个错误。

Sub changeShapePicture(ByRef thisShape As Visio.Shape, filepath as string)

If Dir(filepath) <> "" Then
    Debug.Print "File Exists"
    thisShape.ChangePicture(filepath)
    Else
    Debug.Print "Picture File Doesn't Exist"
End If

我收到“此操作的目标对象不合适”的错误。

该方法表示它将图片高度/宽度比作为双精度值返回。

也试过

dim myRatio as double
myRatio = thisShape.ChangePicture(fullPicPath)

并得到同样的错误。

尝试记录宏没有产生有用的代码。

大多数组织框都有在创建组织结构图时导入的图片。但是,由于谁向谁报告的奇怪安排,需要在辅助操作中添加一些框,这就是我试图自动化的。

任何帮助表示赞赏。

标签: vbavisio

解决方案


弄清楚了。在预定义的组织结构图形状中更改图片的解决方案是使用 Add On

Sub changeShapePicture(ByRef thisShape As Visio.Shape, filePath as string)

dim sendTheseKeys as string

sendTheseKeys = filePath + "{ENTER}"
ActiveWindow.Select thisShape, visDeselectAll + visSelect
Dim adn As Visio.Addon
Set adn = Visio.Addons("OrgC11")
SendKeys sendTheseKeys,False
adn.Run "/cmd=ChangePicture"

end sub

现在完美运行。


推荐阅读