views:

1999

answers:

2

I am trying to run a macro when I double click on Visio shapes. I want to pass the shape object to the VBA macro so that I could do something in the macro depending on the id of the Shape object.

Is it possible to pass the parameter to VBA macro. If yes, please let me know how?

Thanks.

A: 

When you click on an object, the Selection changes. You can use the Selection object in your macro to refer to the currently selected object.

I'm not sure if a macro can be run on double click, but my VBA experience does not come from Visio. As bit of googling turns up that this somehow seems to be possible. If you put it as a Button on a CommandBar, with a little more effort even in the context menu, you would be restricted to a Sub procedure without parameters in any case.

Tomalak
+1  A: 

You can put your macro as the EventDblClick event on the shapes you want to watch. To do this you would use the CallThis function (http://msdn.microsoft.com/en-us/library/aa212649(office.11).aspx) to have your macro called every time a shape is double-clicked.

This would require though, that you modify the shapesheet for every shape you want to watch. If you're providing the master(s) for the shapes you want to watch it shouldn't be a big deal, but otherwise you'd have to write code that will add the event to every shape you want to watch (though you could use the Document_ShapeAdded event on a document to add your event to the shapesheet whenever a shape is added)

Jon Fournier