The SheetId of the reference returned by xlfTextref is not OK, and
causes the error in the xlcFormula call.
As you note, when the sheet name is explicitly added, everything seems
OK.
One way to get a valid reference to the Active sheet is to just create
the ExcelReference with no SheetId - then Excel-DNA will retrieve the
SheetId for the current sheet.
So pseudocode for a workaround would be:
Check whether the string you want to convert to an ExcelReference
contains a sheet name (perhaps search for '!')
if it does, convert the string to a reference using xlfTextref
if it does not,
Extract the row and column values from the string (maybe
with a regex)
Use the row and column (-1 in each case to change to 0-
based index) to make a new ExcelReference using
myRef = new ExcelReference(row - 1, col - 1);
use this ExcelReference instead of the result from
xlfTextref in your call to xlcFormula
Why is the SheetId returned from the xlfTextref not correct, and is
this an Excel bug or an Excel-DNA bug?
I don't know yet.
-Govert