Which control caused the macro to run?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
Hi Jonas

Application.Caller
will return the control name.

HTH. Best wishes Harald
 
Application.Caller was exactly what I was looking for. Thank you all for
taking the time to answer my question.

/Jonas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top