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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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?
Whilst maybe not quite what your user was looking for, this would work.
Code:
Private Sub Blue_Click()
Call ColourCells("Blue")
End Sub


Private Sub Red_Click()
Call ColourCells("Red")
End Sub
And then in a standard module
Code:
Sub ColourCells(Clr As String)
    Dim ClrInd As Long
    Select Case Clr
        Case "Blue"
            ClrInd = 8
        Case "Red"
            ClrInd = 3
    End Select
    Range("A1").Interior.ColorIndex = ClrInd
End Sub
 
Upvote 0
Thanks for your input. Yes I knew there we other ways. Strange there is no way of getting active control name.
Whilst maybe not quite what your user was looking for, this would work.
Code:
Private Sub Blue_Click()
Call ColourCells("Blue")
End Sub


Private Sub Red_Click()
Call ColourCells("Red")
End Sub
And then in a standard module
Code:
Sub ColourCells(Clr As String)
    Dim ClrInd As Long
    Select Case Clr
        Case "Blue"
            ClrInd = 8
        Case "Red"
            ClrInd = 3
    End Select
    Range("A1").Interior.ColorIndex = ClrInd
End Sub
 
Upvote 0
I've used classes for other controls (like to validate inputs), but it didn't occur to me to use a class. Nice work.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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