Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Who's my caller info?

Hi,
Is there a way or a trick to detect in a procedure the name of its caller?

TIA
Paul



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Who's my caller info?

Does a neat trick include keeping track yourself?

Option Explicit
Public myParentCaller As String
Sub test1()
Dim myParentTemp As String
MsgBox "I got called from: " & myParentCaller
myParentTemp = myParentCaller
myParentCaller = "test1"
Call test2
myParentCaller = myParentTemp
MsgBox "I still got called from: " & myParentCaller
End Sub
Sub test2()
Dim myParentTemp As String
MsgBox "I got called from: " & myParentCaller
myParentTemp = myParentCaller
myParentCaller = "test2"
Call test3
myParentCaller = myParentTemp
MsgBox "I still got called from: " & myParentCaller
End Sub
Sub test3()
Dim myParentTemp As String
MsgBox "I got called from: " & myParentCaller
myParentTemp = myParentCaller
'no more calls, just in case...
myParentCaller = myParentTemp
MsgBox "I still got called from: " & myParentCaller
End Sub



count wrote:

Hi,
Is there a way or a trick to detect in a procedure the name of its caller?

TIA
Paul


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Who's my caller info?

Only if it is called from the onaction property of a shape or if it is in a
function called from a worksheet cell. Then you can use application.caller.
If another procedure calls it, you would have to pass in the name of the
procedure by hard coding the name in your code.

--
Regards,
Tom Ogilvy

"count" wrote in message
...
Hi,
Is there a way or a trick to detect in a procedure the name of its caller?

TIA
Paul





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Who's my caller info?

You probably don't need all these possibilities:

Function doTest(Optional arg = "???")
Dim v As Variant
Select Case TypeName(Application.caller)
Case "Range"
v = Application.caller.Address
Case "String"
v = Application.caller
Case "Error"
v = "arg=" & arg
Case Else
v = "unknown"
End Select
doTest = "caller = " & v
End Function

Sub proc1()
Dim x As Variant
MsgBox doTest("proc1")
End Sub

Sub proc2()
Dim x As Variant
MsgBox doTest("proc2")
End Sub



count wrote:
Hi,
Is there a way or a trick to detect in a procedure the name of its caller?

TIA
Paul




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Who's my caller info?

Dave,
Thanks for the solution. Will adapt and adopt.
As this involves work, it doesn't classify as a neat trick - unless one is
an accountant...
:)
Paul
Uzytkownik "Dave Peterson" napisal w wiadomosci
...
Does a neat trick include keeping track yourself?

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Caller Marcelo Excel Discussion (Misc queries) 6 June 23rd 06 03:07 PM
Row = Application.Caller.Row Charles Woll Excel Worksheet Functions 8 February 28th 05 02:04 PM
Application.Caller Mark Worthington Excel Programming 9 February 12th 04 07:32 PM
application.caller Jase Excel Programming 0 January 6th 04 03:51 AM
DDE and application.caller help Ross Kaminsky Excel Programming 1 July 17th 03 04:17 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"