Changing macro button caption

T

The Cube

Hi all

Is it possible (and if so how) to change (within the macro code) the caption
of the button that called it?

If so, in addition to the syntax of the instruction to do this, how do you
identify the button?

Thanks

-Cube
 
D

Dave Peterson

Is this a button from the forms toolbar?

Option Explicit
Sub testme()

Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
myBTN.Caption = "You clicked on me!"

End Sub

If it's a button from the controltoolbox toolbar:

Option Explicit
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Ouch! Not so hard."
End Sub
 
T

The Cube

Thanks, Dave, that answers.

-Cube

Dave Peterson said:
Is this a button from the forms toolbar?

Option Explicit
Sub testme()

Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
myBTN.Caption = "You clicked on me!"

End Sub

If it's a button from the controltoolbox toolbar:

Option Explicit
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Ouch! Not so hard."
End Sub
 
Top