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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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