1

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kamran64
  • 23
  • 4
  • How do you know when to open the userform? In other words, what event are you handling? Also, some code would be helpful. – Zev Spitz Jun 27 '18 at 11:40
  • Hi Zev, I have edited my post to show that the user form macro runs when the shape is dropped onto the screen. (EventDrop). I have also attached my current code. – Kamran64 Jun 27 '18 at 11:55

1 Answers1

4

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.

JohnGoldsmith
  • 2,638
  • 14
  • 26
  • For others like me finding this answer helpful, [this link](http://guides.wmlcloud.com/office/Microsoft-Visio-2010---Introducing-Automation-and-VBA-Code-(part-3)---Calling-VBA-Code-from-a-SmartShape-.aspx) provides some additional example material. – SmrtGrunt Mar 15 '19 at 17:34