问题
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