为什么Application.get_Caller(Type.Missing)返回一个负整数?

get_Caller(Type.Missing)方法有些奇怪。 它返回一个负整数-2146826265 ,而不是Range对象。

有没有人遇到过这个问题? 为什么呢,我该如何解决呢?

谢谢。

 Excel.Range range = (Excel.Range) application.get_Caller(System.Type.Missing); 

上面的代码将失败,如果我尝试显式用户typesExcel.Range 。 错误消息说,'不能将types'int'转换为'Microsoft.Office.Interop.Excel.Range'。

编辑:

获取单元的调用者的意图是将其传递给我的以下function:

 private string getResultFromResultSheet(Excel.Range originalSheetRange, Excel.Worksheet resultSheet) { string DataResult = ""; try { string os_currentAddress = originalSheetRange.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing); Excel.Range currentRRange = null; currentRRange = resultSheet.get_Range(os_currentAddress, Type.Missing); if (currentRRange != null) { if (string.IsNullOrEmpty(Convert.ToString(currentRRange.Value))) DataResult = ""; else DataResult = Convert.ToString(currentRRange.Value); } } catch (Exception ex) { } return DataResult; } 

使用该函数的返回值,我可以将其传递回UDF并将其显示在原始单元格中。 有没有更好的方法来实现该function?

查看此MSDN库文章关于Application.Caller属性的末尾处的表。 你已经发现了#REF的价值! 错误。 谷歌“Excel错误2023”的其他信息。 我有点怀疑你可以使用这个属性,因为调用者是你的C#程序。