View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default UDF - not always calculated



"makulski" wrote in message
...
Yes, after some debugging, the references to ranges are getting confused
when
they are referenced from another active workbook.
I'm having some success in getting this to work.

I replaced references in the UDF that looked like this:
range(MyColLookup)
with this:
MyWorkbook.Names(MyColLookup).RefersToRange

This actually works, but now I have a chicken-and-egg problem.
In my function, I have hardcoded the name of my workbook:
Dim MyWorkbook As Workbook
Set MyWorkbook = Application.Workbooks("Quik3.xls")



This shouldn't be necessary. The way to do it is to tie the range back to
its parent sheet, as I showed you, which automatically ties it back to the
workbook.


How can I have the UDF determine the name of the workbook it is in without
my actually having to type it into the code?
I see in the Project explorer the module is under VBAProject(Quik3.xls)
Can the code reference its own parent?



Yes it can, it is called ThisWorkbook. But as I said, it ain't necessary.


(By the way, thanks for the quick replies to my questions. I hope
somebody
is paying you for this attention :-)



Nope, we do it gratis. Anyway, I am off to bed, so you won't see me again
until tomorrow now.