Possible to know who has called a function ?

C

Chip Pearson

Isabelle,

There is no way to programmatically determine what procedure
called another procedure. In debug mode, you can view the call
stack (View menu, Call Stack), but this is not available
programmatically.


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

Isabelle Robin

Hi to all,

I would like to know if it is possible to know who has called a certain
function.

For example, I have three functions "printPage", "printPage1",
"printPage2" which can called another function "PrintToPdf".
I'm am in the "PrintToPdf" function. Is it possible to know which
function has called me ?

Thks for your answer

Best regards
 
J

Jim Cone

Isabelle,

You can use a different argument in each calling function,
then identify the argument in the called function, something like...

'-----------------------
Function PrintPage()
PrintToPdf (0)
End Function

Function PrintPage1()
PrintToPdf (1)
End Function

Function PrintPage2()
PrintToPdf (2)
End Function

Function PrintToPdf(ByRef F As Long)
Select Case F
Case 0
'Do some code
MsgBox F
Case 1
'Do different code
MsgBox F
Case 2
'Do really different code
MsgBox F
End Select
End Function
'--------------------------

Regards,
Jim Cone
San Francisco, CA
 
R

Robin Hammond

Chip's right, but if you wanted to edit your code you could always pass the
routine a parameter.

Sub MySub(strCaller as string)
debug.print strCaller
'do stuff
End Sub

Calling routines like this

Sub1
MySub "1"
End Sub

Sub 2
MySub "2"
End Sub

Robin Hammond
www.enhanceddatasystems.com
 
Top