MassSpecGuru
Board Regular
- Joined
- Feb 23, 2010
- Messages
- 55
I have an Excel 2003 workbook that has many buttons on different worksheets within it and I was wondering if there is a way to tell which button was clicked?
MsgBox Application.Caller
If they are "Form" buttons and all calling the same procedure you can use:
Code:MsgBox Application.Caller
Gary
Public Sub Button_Click()
Select Case Application.Caller
Case "Button 1" 'Use actual button names
'code for button 1
MsgBox "Button 1 clicked"
Case "Button 2"
'code for button 2
'case "More buttons"
Case Else
'Any other buttons that do the same thing
End Select
End Sub
Dim sButton As String
sButton = Application.Caller
MsgBox sButton
I usually use "Select Case" for something like this:
Code:Public Sub Button_Click() Select Case Application.Caller Case "Button 1" 'Use actual button names 'code for button 1 MsgBox "Button 1 clicked" Case "Button 2" 'code for button 2 'case "More buttons" Case Else 'Any other buttons that do the same thing End Select End Sub
Or if you prefer:
Code:Dim sButton As String sButton = Application.Caller MsgBox sButton
Gary
Whenever I try it or your previous suggestion (either with or without debug. print) from within the VB Editor window I get a:
"Run-time error '13': Type mismatch"
error message.