VBA: how to get text displayed on form control button

dmash

New Member
Joined
Mar 29, 2010
Messages
40
Hello,

Does anyone know the VBA syntax used to get the text displayed on a form control button?

This is not the name of the button, which can be retrieved using application.caller, but the text on top of the button itself.

Thanks,
Don.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Tinkering around using the macro recording, I found one solution.

ActiveSheet.Shapes(Application.Caller).Select
Range("H2") = Selection.Characters.Text

but I cannot combine it into one command line,
Range("H2") = ActiveSheet.Shapes(Application.Caller).Characters.Text

Anyone knows why?
 
Upvote 0
Follow up question.

How do I change the display text of a form control button? I'd like to change the display text to the value of cell A2.

I got this from macro recording.
Code:
ActiveSheet.Shapes("Button 2").Select
Selection.Formula = "=A2"

Combining that into one liner gives me an error.
Code:
ActiveSheet.Shapes("Button 2").Formula = "=A2"
What is the correct syntax?

Thanks.
 
Upvote 0
AlternativeText is what a web browser sees in some situations. It is intially set to the text of the button, but is not what the user sees when running excel.

To set or read the text on a Forms Button,

Code:
With ActiveSheet
    .Shapes("Button 2").TextFrame.Characters.Text = CStr(.Range("A2").Value)
End With
 
Upvote 0
AlternativeText is what a web browser sees in some situations. It is intially set to the text of the button, but is not what the user sees when running excel.

To set or read the text on a Forms Button,

Code:
With ActiveSheet
    .Shapes("Button 2").TextFrame.Characters.Text = CStr(.Range("A2").Value)
End With

Thank you. Your code works wonderfully for both setting and reading text.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

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