Change Control Toolbox Button Caption

O

Otto Moehrbach

Excel XP & Win XP

I have a Control Toolbox button, "CommandButton1" with a caption of, say,
"Old Caption".

I want to change the caption via VBA to, say, "New Caption".

How do I code that?

Thanks for your time. Otto
 
O

Otto Moehrbach

Per
Thanks for your response but I don't have a UserForm. The button is a
simple Control Toolbox button on the sheet. Otto
 
P

Peter T

Dim ole As OLEObject

On Error Resume Next
Set ole = ActiveSheet.OLEObjects("CommandButton1")
On Error GoTo 0

If Not ole Is Nothing Then
ole.Object.Caption = "New Caption"
Else
msgbox "no oleObject named CommandButton1 on activesheet"
End If

Regards,
Peter T
 
D

Dave Peterson

ActiveSheet.CommandButton1.Caption = "hi there"
'or
ActiveSheet.OLEObjects("commandbutton1").Object.Caption = "bye now"
 
O

Otto Moehrbach

Peter, Dave
Thanks. Works like a charm. Otto
Dave Peterson said:
ActiveSheet.CommandButton1.Caption = "hi there"
'or
ActiveSheet.OLEObjects("commandbutton1").Object.Caption = "bye now"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top