Setting button name with Shape object (xlButtonControl)

MichaelOar

New Member
Joined
Oct 13, 2008
Messages
5
Hello,

Can't find an answer that's working for me. I need to programatically add a button, rename the button text and link to a macro. I got what I thought was the hard stuff (macro assignment, button creation, placement, etc), but I can't for the life of me figure out how to NAME the thing. There is a Shape.Name attribute, but this doesn't seem to change the text displayed on the button. Other posts I've seen have said to use the "Caption" attribute for buttons and/or to use "command buttons". When I use the VBA help and look at the examples I can find on the web, they tell me to do something like this:

Dim myButton As Shape
With Worksheets(mySheet.Name)
Set myButton = .Shapes.AddFormControl(xlButtonControl, 50, 325, 80, 60)
End With

Again, can't find a way to set the button text/name. I tried:

myButton.Name = "My Name"

but that isn't working.

Any help would be greatly appreciated.

-Mike
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
With ActiveSheet.Shapes
    With .AddFormControl(xlButtonControl, 50, 325, 80, 60)
        .OnAction = "mySub"
        With .TextFrame
            .Characters.Text = "Press Me"
        End With
    End With
End With
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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