Senin, 22 Desember 2014

Re: [ExcelVBA] Detect which shape "starts" a macro


Tim and Derek! Thank you for your suggestions, I'll try to check it out in a day or four. But as you know there are several family days coming soon, not much time for VBA.

And then I'll try to explain another approach that I found too. 


Den 21. des. 2014 kl. 21.34 skrev 'Tim Lewis' [ExcelVBA] <>:


Hi Torstein,


Here is an example of identifying the name:


Sub IdentifyShape()

Dim strShapeName As String

strShapeName = ActiveSheet.Shapes(Application.Caller).Name

MsgBox "The shape name is " & strShapeName

End Sub


to base code on the name would be:

If strShapeName = "Shape1" Then

                'do stuff

End If


If you need to know the names of all shapes, use this:

Sub IdentifyShapes()
Dim strShapeName As String
For Each Shape In ActiveSheet.Shapes
    Shape.Select  ' This shows which shape is the current shape
    strShapeName = Shape.Name


'If you need to rename a shape to a more meaningful name, use this

   ' If Shape.Name = "Shape1" Then
       ' Shape.Name = "GetNewData"
   'End If

End Sub




I hope that you have a great Christmas and New Year.






From: []
Sent: Sunday, December 21, 2014 9:26 AM
Subject: [ExcelVBA] Detect which shape "starts" a macro



In a worksheet there are several shapes.


They are all assigned to the same macro.


Is it possible in the macro to detect which skape that was "clicked on" to start the macro?


I wish the macro to do different tasks dependent on which shape that started it!


Is there a sort of activeShape object?


Regards and Merry Christmas to all of you Excelers!


Torstein Johnsen


Posted by: Torstein Johnsen <>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: to enter the ezine, then search the ARCHIVES for EXCEL VBA.

Visit our ExcelVBA group home page for more info and support files:

More free tutorials and resources available at:




Tidak ada komentar:

Posting Komentar