Finding id of shape dragged onto screen in Visio using VBA macro

喜欢而已 提交于 2019-12-11 06:46:18

问题


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.

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.

Image: Shapesheet of the shape running the macro on drop. "Form" is the user form.

Image: Userform macro

I would be very grateful if someone could help me with this problem.

Thank you


回答1:


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")

and then add this backing code:

Public Sub OnMyShapeDrop(shp As Visio.Shape)
    MsgBox "Shape dropped - ID = " & shp.ID, vbOKOnly, "Shape Dropped"
End Sub

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.



来源:https://stackoverflow.com/questions/51061741/finding-id-of-shape-dragged-onto-screen-in-visio-using-vba-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!