PDA

View Full Version : Solved: Click a command button to get the name of the previous button clicked



frank_m
03-14-2012, 12:16 PM
In Excel 2003, Using sheet type activex command buttons, I would like to be able to have code in one button that will give me the name (in a msgbox) of the previous button that was clicked .

Thanks

p45cal
03-14-2012, 12:33 PM
In the sheet's code module:
Dim LastButtonClicked As String' global variable. Put at top of module.
Private Sub CommandButton1_Click()
LastButtonClicked = CommandButton1.Name
'LastButtonClicked = CommandButton1.Caption
End Sub

Private Sub CommandButton2_Click()
LastButtonClicked = CommandButton2.Name
'LastButtonClicked = CommandButton2.Caption
End Sub

Private Sub CommandButton3_Click()
LastButtonClicked = CommandButton3.Name
'LastButtonClicked = CommandButton3.Caption
End Sub

Private Sub CommandButton4_Click()
LastButtonClicked = CommandButton4.Name
'LastButtonClicked = CommandButton4.Caption
End Sub

Private Sub CommandButton5_Click() 'This is the new button.
MsgBox LastButtonClicked
End Sub

frank_m
03-14-2012, 12:55 PM
Thank you Sir :thumb

(another one I should have realized on my own) :think: :bug: :mkay :whistle: :giggle :)