1

VB6 可以打开 Excel 工作簿并读取单元格的值,即使该单元格包含使用用户定义函数的公式;但是,VB.NET 2012 总是返回错误代码 (0x800A07ED) 而不是值。有谁知道如何哄 VB.NET 返回单元格的实际值?


当单元格的公式包含 UDF 时,VB.NET 会失败。例如,单元格的公式可以是=MyFunction(A1)(其中 MyFunction 是公共模块中的公共函数)。

' A1's Value is "123".
' B1's Formula is "=MyFunction(A1)".
'
' After opening the workbook with VB.NET:
Dim rng1Cell As Excel.Range
rng1Cell = Sheet1.Range("B1")

Dim dblValue As Double
dblValue = CType(rng1Cell.Value, Double)

' dblValue now equals 0x800A07ED
4

0 回答 0