Senin, 22 Desember 2014

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


This is more simple :-

    strShapeName = Application.Caller


Derek Turner +++

From: "'Tim Lewis' [ExcelVBA]" <>
Sent: Sunday, 21 December 2014, 20:34
Subject: RE: [ExcelVBA] Detect which shape "starts" a macro

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: Derek Turner <>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
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