Finding id of shape dragged onto screen in Visio u

2019-08-02 02:21发布

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条回答
成全新的幸福
2楼-- · 2019-08-02 02:35

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.

查看更多
登录 后发表回答