使用 VBA 宏在 Visio 中查找拖到屏幕上的形状 ID [英] Finding id of shape dragged onto screen in Visio using VBA macro

查看:81
本文介绍了使用 VBA 宏在 Visio 中查找拖到屏幕上的形状 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 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屋!

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