Who called this method?

ScottInTexas

Board Regular
Joined
Oct 28, 2003
Messages
178
Is there a way to identify which method calls another. I have a method called from several others. I would like to know which caller it was. Application.Caller is not for this. I want to do something like this.
Code:
 Debug.Print "In write data method." & WhoCalledIt

Thanks,
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You can't access the call stack from VBA, but the calling routine can pass its name via an argument.
 
Last edited:
Upvote 0
Or you could create your on call stack with a public collection that every procedure pushes on entry and pops on exit.
 
Upvote 0
Not sure this is the same thing but:

If I click on a activex control to run a script. How can I get the name of the activex button I just clicked on?
I want the name not the caption.
Using Vba

Or you could create your on call stack with a public collection that every procedure pushes on entry and pops on exit.
 
Upvote 0
An ActiveX control runs its own click event. For a control on a worksheet, you can hard-code the control name in the event. For a control on a userform, maybe userform.activecontrol, but I've not used it.
 
Upvote 0
Would you care to tell me how to do this:
You said:
For a control on a worksheet, you can hard-code the control name in the event

I've tried something like this but it does not work
Code:
Dim ans as string
ans=Activecontrol.Name

An ActiveX control runs its own click event. For a control on a worksheet, you can hard-code the control name in the event. For a control on a userform, maybe userform.activecontrol, but I've not used it.
 
Upvote 0
On a worksheet:

Code:
Private Sub CommandButton1_Click()
  MsgBox "Button1 reporting for duty"
End Sub

On a userform:

Code:
Private Sub CommandButton1_Click()
  MsgBox ActiveControl.Name
End Sub
 
Upvote 0
I'm sorry but a user here last week wanted to do this:

When I click on Activex command button named "Blue" he wanted "Blue" entered into Range("A1")

When I click on Activex command button named "Yellow" I want "Yellow" entered into Range("A1")

That's why I need to know the name of the activex command button that was clicked.
He had like 20 of these command buttons and did not want to put a script in each command button.

So your saying we cannot get the name of the Activecontol if it's in a sheet like we can if it's on a UserForm?
 
Upvote 0
So far as I know, no.

Jaafar could probably hook something in API to find out.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top