How can I get the ID from the active shape (shape with focus)

F

Frank

Hello,
I made a shape that starts a Visio-VBA-code after a double-click.
Than I copy this shape ten or more times to a page (all uses the same
VBA-code).
My problem is, that I don´t get a information which shape creates the
double-click-event if I click twice to one of this shapes.
How can I get the shape ID after a double-click?
Thank´s
Frank
 
J

John

Hello Frank,

The procedure that you call from your double click event is automatically
passed a reference to that shape. So, for example, you could try this
procedure:

Sub GetShapeID(ByRef shpIn As Visio.Shape)
MsgBox ("This shape's ID is: " & shpIn.ID)
End Sub

....which would be called by a formula in the EventDblClick cell:
=CALLTHIS("GetShapeID")

Hope that helps.

Best regards

John
 
F

Frank

Thank´s for your reply.
That´s the normale way of getting a access to the item that creates the click.
But I started this macro from a shape->format->behavior->double-click->start
macro. There you can start any public VBA-code from Visio´s VBA. But I can´t
give them any transfer parameter. And if I create a code like you show below,
you will get an fault message. It is funny, there is a property for the
activewindow and for activepage in visio, but there is no property for the
active shape/item .....!!
I create a not nice work-around. I have to push one button that starts my
VBA script and looks to all shape on the page, but that´s not perfect.

Thank´s
Frank
 
J

John

Hello Frank,

Where have you placed your code/macro (in a stencil or a normal document)?
It should work but let me know what error message you're getting.

To just get a reference to the active shape, use ActiveWindow.Selection as
below:

Sub GetActiveShapeID()
Dim shp As Visio.Shape
Set shp = ActiveWindow.Selection.PrimaryItem
MsgBox ("The active shape's ID is: " & shp.ID)
End Sub

Bear in mind that ActiveWindow.Selection will return a collection of 0 to n
shapes depending on the current selection. The PrimaryItem property returns
a reference to a single shape within that selection.

Best regards

John
 
F

Frank

Perfect, that´s works.
Your "Sub GetActiveShapeID()" helps and is exactly what I need.
Thank´s
Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top