AutoShape

S

skid812pb

Is there a way to automaticlly assign a macro to and autoshape object in VB,
if there is Could some please help. Thanks.
 
B

Bob Phillips

ActiveSheet.Shapes("Autoshape 2").OnAction = "myMacro"

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
S

skid812pb

Thanks that worked great, but now I have another problem, I have several
autoshapes on my worksheet and I need to find a way to tell which shape was
selected if it is possible

Thanks again
 
D

Dave Peterson

You're assigning the same macro to various shapes and want to determine which
shape was clicked on to start the macro?

If yes, then you can use Application.caller to get the name of the shape. And
you can find out more about the shape, too:

Option Explicit
Sub testme()

Dim myShape As Shape

MsgBox Application.Caller

Set myShape = ActiveSheet.Shapes(Application.Caller)

With myShape
MsgBox .Name & vbLf & .TopLeftCell.Address
End With

End Sub
 
S

skid812pb

Thanks Dave, That is what I was Lookin for.

Dave Peterson said:
You're assigning the same macro to various shapes and want to determine which
shape was clicked on to start the macro?

If yes, then you can use Application.caller to get the name of the shape. And
you can find out more about the shape, too:

Option Explicit
Sub testme()

Dim myShape As Shape

MsgBox Application.Caller

Set myShape = ActiveSheet.Shapes(Application.Caller)

With myShape
MsgBox .Name & vbLf & .TopLeftCell.Address
End With

End Sub
 
S

Scoop

Hi Dave,

Just found this thread. I was looking for something similar, BUT, when
selecting the shape, I want the shape name to be used as criteria1 in my
small one liner macro .... Selection.AutoFilter Field:=1, Criteria1:="M/162",
rembering I hav many shapes and do not want an individual macro for each.

Cheers
 
D

Dave Peterson

Check your other post.

But your criteria seems to have changed.

I wouldn't use slashes in names of shapes. I'd use an underscore.

So if you're using xl2k or higher, make a change:

...., Criteria1:=" " & replace(myShape.Name, "_", "/")
 
Top