ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   private sub- which procedure called it (https://www.excelbanter.com/excel-programming/341213-private-sub-procedure-called.html)

SUNIL

private sub- which procedure called it
 

When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below to be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

.....run code depending on which procedure has called this sub routine

End sub




Chip Pearson

private sub- which procedure called it
 
There is no built-in way to determine what procedure called
another. The only way would be to create a public variable, put
the caller's name in that variable, and read that variable in the
routine.

[in module1]
Public WhoCalled As New Collection

Sub AAA()
WhoCalled.Add "AAA"
' more code
End Sub

[in ThisWorkbook]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CalledBy As String
CalledBy = WhoCalled(WhoCalled.Count)
Select Case CalledBy
Case "AAA"
' do something
Case "BBB"
' do something else
Case ....
End Select

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sunil" wrote in message
...

When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below to
be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

....run code depending on which procedure has called this sub
routine

End sub






Chip Pearson

private sub- which procedure called it
 
Small revision.....

Change

CalledBy = WhoCalled(WhoCalled.Count)
' to
CalledBy = WhoCalled(WhoCalled.Count)
WhoCalled.Remove WhoCalled.Count


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
There is no built-in way to determine what procedure called
another. The only way would be to create a public variable,
put the caller's name in that variable, and read that variable
in the routine.

[in module1]
Public WhoCalled As New Collection

Sub AAA()
WhoCalled.Add "AAA"
' more code
End Sub

[in ThisWorkbook]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CalledBy As String
CalledBy = WhoCalled(WhoCalled.Count)
Select Case CalledBy
Case "AAA"
' do something
Case "BBB"
' do something else
Case ....
End Select

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sunil" wrote in message
...

When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below
to be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

....run code depending on which procedure has called this sub
routine

End sub









All times are GMT +1. The time now is 10:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com