Finding the name of a shape/button I clicked

ss123

New Member
Joined
Mar 4, 2014
Messages
23
I have a tool I am preparing for a friend as he now has an age related issue of tremor filled hands. It is a budget tool. Instead of having a listbox with the months of the year in it, which he cannot properly click on the correct month because the default font is too small and his hand shakes too much, I inserted 12 equally sized rounded, huge rectangular shapes with the months of the year on them.

I then renamed each button with the month name it represents. Why? I want one procedure to get the shape/button that was clicked and get me its name. As such I can then feed the correct budget to show for my friend. The code once I have the shape's name is easy. Getting the shape's name is not (at least for me).

As an aside, I did search for this issue on your site and came up with this code (provided by one of your specialists):

MsgBox ActiveSheet.Buttons(Application.Caller).Caption

But it gives me the runtime error of 1004 and says:
Unable to get the Buttons property of the Worksheet class

Since I am using a shape, I tried:
MsgBox ActiveSheet.Shapes(Application.Caller).Caption

and then I get another error with:
'-2147352571 (80020005)'
The item with the specified name wasn't found

Can anyone help me?

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Ok, I finally found it on my own. I had the macro from another time, but I was running it from the code window and from there, since I had not clicked on any shape, it was giving me an error. Otherwise, if you click on the shape to which you assigned this code, it should work and as such, if you have multiple shapes, you only need this one sub routine to identify which shape you clicked on.

Sub GetName()
Dim Nme As String
Nme = ActiveSheet.Shapes(Application.Caller).Name

MsgBox Nme

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top