• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need button name after applying macro

coolsac12

Member
Hi,

If I run a macro and it is assigned to a button "Button 1", I want "Button 1" as output after clicking on button.

Could you please help on this code.

Thanks in advance
 
Hello Collsac12.
ACTIVE X CONTROL BUTTON

Try This.

Code:
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Button1" Then
    CommandButton1.Caption = "Output"
Else
CommandButton1.Caption = "Button1"
End If
End Sub
 
Last edited:
Hello Collsac12.

FORM CONTROL BUTTON

Code:
Public Sub Change_Caption()
  
    With ActiveSheet.Buttons("Button 1")
      
        If .Caption = "Button 1" Then
                      
            .Caption = "Output"
        Else
            .Caption = "Button 1"
        End If
    End With
End Sub


Thanks #Monty for your instant help.

Let me tell you what problem I am facing. Actually I have some pictures in my sheet and I have assigned same userform to all the pictures. Now I want the picture name on which I have clicked to run the macro. (I have to apply If condition on that result)

Thanks a ton Monty :)
 
Back
Top