Changing macro button caption

  • Thread starter Thread starter The Cube
  • Start date Start date
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
 
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
 
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
 
Back
Top