Here is the code that converts an ExcelReference to a Range, and it can be called from a UDF without errors
private static Range ToRange(ExcelReference reference)
{
var xlApp = ExcelDnaUtil.Application as Application;
var item = XlCall.Excel(XlCall.xlSheetNm, reference) as string;
int index = item.LastIndexOf(']');
item= item.Substring(index+1);
var ws = xlApp.Sheets[item] as Worksheet;
var target = xlApp.Range[
ws.Cells[reference.RowFirst+1, reference.ColumnFirst+1],
ws.Cells[reference.RowLast+1, reference.ColumnLast+1] ] as Range;
return target;
}
As you can see, you have to call
xlSheetNm that returns something like "
[WorkbookFile.xls]Sheet1" and the name of the sheet must be parsed and used to get the worksheet reference. Finally, a range object is built from the table of cells in this worksheet.