Detect which shape was clicked....

T

Thief_

IF I have 3 autoshapes, rectangles, on a worksheet, how do I detect which
shape was clicked by the user so that I can, say, delete it or change its
properties?

Thanks.
 
N

Norman Jones

Hi Thief,

Try assigning ththe following macro to each of thre rectangles:

Sub TestRectangles()

Select Case Application.Caller
Case "Rectangle 1"
'Do something
MsgBox Application.Caller '<<=== Demo only
Case "Rectangle 2"
'Do something
MsgBox Application.Caller '<<=== Demo only
Case "Rectangle 3"
'Do something
MsgBox Application.Caller '<<=== Demo only
End Select

End Sub


Change the names of the rectangles to accord with your names.

Replace the 'Do something lines with your desired actions.

The MsgBox lines are purely for demo purposes; click the rectangles and
test.
 
T

Thief_

TOP post Norman!!

--
|
+-- Thief_
|

Norman Jones said:
Hi Thief,

Try assigning ththe following macro to each of thre rectangles:

Sub TestRectangles()

Select Case Application.Caller
Case "Rectangle 1"
'Do something
MsgBox Application.Caller '<<=== Demo only
Case "Rectangle 2"
'Do something
MsgBox Application.Caller '<<=== Demo only
Case "Rectangle 3"
'Do something
MsgBox Application.Caller '<<=== Demo only
End Select

End Sub


Change the names of the rectangles to accord with your names.

Replace the 'Do something lines with your desired actions.

The MsgBox lines are purely for demo purposes; click the rectangles and
test.
 

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