ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Where was I called from? (https://www.excelbanter.com/excel-programming/428264-where-i-called.html)

Prof Wonmug

Where was I called from?
 
What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?

[email protected]

Where was I called from?
 
Try Worksheet.name in the Immediate Window

Prof Wonmug wrote:

What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?


Rick Rothstein

Where was I called from?
 
Are these what you are looking for...ActiveWorkBook.Name, ActiveSheet.Name,
ActiveCell.Address?

--
Rick (MVP - Excel)


"Prof Wonmug" wrote in message
...
What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?



JLGWhiz[_2_]

Where was I called from?
 
Here is something out of the VBA help files.

This example displays information about how Visual Basic was called.

Select Case TypeName(Application.Caller)
Case "Range"
v = Application.Caller.Address
Case "String"
v = Application.Caller
Case "Error"
v = "Error"
Case Else
v = "unknown"
End Select
MsgBox "caller = " & v


"Prof Wonmug" wrote in message
...
What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?




Niek Otten

Where was I called from?
 
Look at Application.Caller (.Address)
Remember that the active sheet/book doesn't have to be the one that a UDF
was called from
It all depends on what you're trying to achieve. Maybe you should post that.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Prof Wonmug" wrote in message
...
What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?



Prof Wonmug

Where was I called from?
 
On Sat, 9 May 2009 15:48:44 -0400, "Rick Rothstein"
wrote:

Are these what you are looking for...ActiveWorkBook.Name, ActiveSheet.Name,
ActiveCell.Address?


Yup. Thanks.

In these examples, is the first field called an "object" and the
second a "property"?

Is there a nice concise list of the first field, with sublists for the
second (and third?)?

Prof Wonmug

Where was I called from?
 
On Sat, 9 May 2009 16:01:36 -0400, "JLGWhiz"
wrote:

Here is something out of the VBA help files.

This example displays information about how Visual Basic was called.

Select Case TypeName(Application.Caller)
Case "Range"
v = Application.Caller.Address
Case "String"
v = Application.Caller
Case "Error"
v = "Error"
Case Else
v = "unknown"
End Select
MsgBox "caller = " & v


"Prof Wonmug" wrote in message
.. .
What property do I need to qeury to obtain the name of the workbook,
sheet, and cell where a UDF or macro was called?


Thanks. I'll have to study that one.

Prof Wonmug

Where was I called from?
 
On Sat, 9 May 2009 22:29:15 +0200, "Niek Otten"
wrote:

Look at Application.Caller (.Address)


Both of those get an error in the immediate window when the UDF is
running.

Remember that the active sheet/book doesn't have to be the one that a UDF
was called from
It all depends on what you're trying to achieve. Maybe you should post that.


I'm just trying to determine which cell in which sheet called the UDF.
Rick's solution gave me what I needed.

Rick Rothstein

Where was I called from?
 
In these cases, yes; however, if the second ones ever performed an action as
opposed to simply returning a value, then they would be called methods.

--
Rick (MVP - Excel)


"Prof Wonmug" wrote in message
...
On Sat, 9 May 2009 15:48:44 -0400, "Rick Rothstein"
wrote:

Are these what you are looking for...ActiveWorkBook.Name,
ActiveSheet.Name,
ActiveCell.Address?


Yup. Thanks.

In these examples, is the first field called an "object" and the
second a "property"?

Is there a nice concise list of the first field, with sublists for the
second (and third?)?



Charles Williams

Where was I called from?
 
Rick's solution only works if the UDF is called from whatever sheet happens
to be the active sheet:
If you call the UDF from 2 separate worksheets it is bound to give the wrong
answer.

As Niek was pointing out inside a UDF you need:

Application.Caller.Address for the address of the cell that called the UDF
Application.Caller.Parent.Name for the name of the worksheet containing the
cell that called the UDF

(Application.Caller returns a Range object referring to the cell that called
the UDF)

regards
Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Prof Wonmug" wrote in message
...
On Sat, 9 May 2009 22:29:15 +0200, "Niek Otten"
wrote:

Look at Application.Caller (.Address)


Both of those get an error in the immediate window when the UDF is
running.

Remember that the active sheet/book doesn't have to be the one that a UDF
was called from
It all depends on what you're trying to achieve. Maybe you should post
that.


I'm just trying to determine which cell in which sheet called the UDF.
Rick's solution gave me what I needed.





All times are GMT +1. The time now is 05:07 PM.

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