![]() |
Which control caused the macro to run?
Hi!
I have multiple controls (checkboxes) that I've tied to the same macro with the OnAction property. How do I find out which control triggered the macro. I guess that I could dynamically add a unique version of the same macro to all the different controls, but I'd rather have one version of the macro work for all the controls. Thanks, Jonas |
Which control caused the macro to run?
What sort of checkboxes?
Forms Toolbar? Select Case Application.Caller Case "Check Box 1": MsgBox "Checkbox1" Case "Check Box 2": MsgBox "Checkbox2" Case "Check Box 3": MsgBox "Checkbox3" End Select -- HTH Bob Phillips "josa01" wrote in message ... Hi! I have multiple controls (checkboxes) that I've tied to the same macro with the OnAction property. How do I find out which control triggered the macro. I guess that I could dynamically add a unique version of the same macro to all the different controls, but I'd rather have one version of the macro work for all the controls. Thanks, Jonas |
Which control caused the macro to run?
Hi Jonas,
Look at the Caller property in VBA help. To demonstrate, assign the following macro to a control: Sub ATest() MsgBox Application.Caller End Sub --- Regards, Norman "josa01" wrote in message ... Hi! I have multiple controls (checkboxes) that I've tied to the same macro with the OnAction property. How do I find out which control triggered the macro. I guess that I could dynamically add a unique version of the same macro to all the different controls, but I'd rather have one version of the macro work for all the controls. Thanks, Jonas |
Which control caused the macro to run?
Hi Jonas
Application.Caller will return the control name. HTH. Best wishes Harald "josa01" skrev i melding ... Hi! I have multiple controls (checkboxes) that I've tied to the same macro with the OnAction property. How do I find out which control triggered the macro. I guess that I could dynamically add a unique version of the same macro to all the different controls, but I'd rather have one version of the macro work for all the controls. Thanks, Jonas |
Which control caused the macro to run?
Application.Caller was exactly what I was looking for. Thank you all for
taking the time to answer my question. /Jonas "Bob Phillips" wrote: What sort of checkboxes? Forms Toolbar? Select Case Application.Caller Case "Check Box 1": MsgBox "Checkbox1" Case "Check Box 2": MsgBox "Checkbox2" Case "Check Box 3": MsgBox "Checkbox3" End Select -- HTH Bob Phillips "josa01" wrote in message ... Hi! I have multiple controls (checkboxes) that I've tied to the same macro with the OnAction property. How do I find out which control triggered the macro. I guess that I could dynamically add a unique version of the same macro to all the different controls, but I'd rather have one version of the macro work for all the controls. Thanks, Jonas |
All times are GMT +1. The time now is 06:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com