View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Calling workbook and worksheet

Function testUDF(a, b)
' udf in an addin
Dim ws As Worksheet
Dim wb As Workbook
Dim sAddr$
With Application.Caller
sAddr = .Address
Set ws = .Parent
Set wb = .Parent.Parent
End With
s = "[" & wb.Name & "]" & ws.Name & "!" & sAddr

testUDF = s & " = " & a * b
End Function

It would of course be more efficient to pass the range object as you say.

Regards,
Peter T

"Anders" wrote in message
...
I have an add-in, which provides certain user defined functions to xl.

However, an argument of some of these functions is a text string
representing the name of a defined range in the "calling"
workbook/worksheet", which does not get resolved correctly on recalcs of
in-active workbooks/sheets. For this reason, it would be useful to be

able
to get information (in vba) on from which workbook and worksheet a

function
call is beeing made. Is this possible and if so how??? Bwetter

programming
(passing the range) could avoid this problem, but we're stuck with what we
have a need the fix to be backwards compatible...