使用 VBA 宏在 Visio 中查找拖到屏幕上的形状 ID [英] Finding id of shape dragged onto screen in Visio using VBA macro
问题描述
我目前在 Visio 中有一个程序,当我的自定义模具中的特定形状被拖到屏幕上时,会出现一个用户表单并询问用户一个带有组合框的问题,供用户选择答案.
I currently have a program in Visio that when a specific shape in my custom stencil is dragged onto the screen, a user form comes up and asks the user a question with a combo box used for the user to select an answer.
根据选择的答案,该对象的形状数据应该会发生变化.
Based on the answer selected, the shape data should change for that object.
我面临的问题是我不确定如何自动定位形状的 ID,然后更改其形状数据.由于可能放置多个这些形状,我无法为每个 ID 手动编写一段新代码.
The problem that I am facing is that I am not sure how to target the ID of the shape automatically to then change its shape data. Since multiple of these shapes may be placed, I can not manually write a new piece of code for every ID.
如果有人能帮我解决这个问题,我将不胜感激.
I would be very grateful if someone could help me with this problem.
谢谢
推荐答案
我想知道 CALLTHIS
ShapeSheet 函数在这里是否更有用,因为它传递对调用形状的引用.因此,例如,在 EventDrop
单元格中添加以下公式:
I wonder if the CALLTHIS
ShapeSheet function might be more useful here as it passes a reference to the calling shape. So, for example, in the EventDrop
cell add this formula:
CALLTHIS("ThisDocument.OnMyShapeDrop","Drawing001")
然后添加此支持代码:
Public Sub OnMyShapeDrop(shp As Visio.Shape)
MsgBox "Shape dropped - ID = " & shp.ID, vbOKOnly, "Shape Dropped"
End Sub
请注意,我已将代码放在 ThisDocument
类中,但它可以存在于任何可访问的模块中.还要注意项目名称 (Drawing001),它可能是没有扩展名的文件名.
Note, that I've put the code in the ThisDocument
class, but it can live in any accessable module. Also note the project name (Drawing001) which will likely be the file name without the extension.
这篇关于使用 VBA 宏在 Visio 中查找拖到屏幕上的形状 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!