Get button caption when is clicked

cgcamal

Active Member
Joined
May 2, 2007
Messages
472
Hi to all,

I have 30 useform buttons in a sheet (main sheet) and I have 30 sheets more. There is a button for each sheet name, so the caption of each button is the same of the sheet name. E.g:
--------------------------------------------------------------------
Main Sheet name=Main
Sheet1 name= S1 and the caption of button1=Store 1
Sheet2 name= S2 and the caption of button2=Store 2
.
.
.
Sheet30 name= S30 and the caption of button30=Store 30
--------------------------------------------------------------------
When button "Store X" is clicked I want to show (select) respective sheet Sheets("SX").

How can I get the caption of any button clicked to know which sheet the user want to be displayed? Is there an event for this?

Thanks in advance.

Regards.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
For anybody interested in the future, I got the solution using Application.Caller as in the example of Juan P. G. on post:

Retrieve Command Button Caption

Code:
[FONT=Courier New][COLOR=darkblue]Sub[/COLOR] Butt*******ed_Caption()
    [COLOR=darkblue]Dim[/COLOR] St [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], Shp [COLOR=darkblue]As[/COLOR] Shape
    St = Application.Caller
    [COLOR=darkblue]Set[/COLOR] Shp = Sheet1.Shapes(St)
    ButtCap = Shp.TextFrame.Characters.Text
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
Many thanks as always.

Best regards.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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