从.NET中的VBA函数访问返回值? [英] Access return value from VBA Function in .NET?
问题描述
我在VBA(位于Excel 2007工作簿中)中具有以下代码:
I have the following code in VBA (which resides in an Excel 2007 Workbook):
Public Function Multiply(a As Double, b As Double) As Double
Multiply = a * b
End Function
如果我从其他VBA代码中调用Multiply,它将返回正确的值.但是,当我从C#调用乘:
If I invoke Multiply from other VBA code, it returns the correct value. However, when I call Multiply from C#:
var excel = new Application {Visible = true};
excel.Workbooks.Open(filename);
var returned = excel.Run("Sheet1.Multiply", (Double) a, (Double) b);
...发生了乘法运算(我可以通过在VBA中的Multiply函数中添加跟踪来验证这一点),但是返回的值在我的C#代码中不可用; returned
始终为null
.
... the multiplication takes place (I can verify this by adding tracing to the Multiply function in VBA) but the returned value isn't available in my C# code; returned
is always null
.
有人可以告诉我如何从我的C#代码中获得Multiply的返回值吗?
Could someone please tell me how to get at the return value of Multiply from my C# code?
推荐答案
您是否尝试过将函数移至Excel中的常规模块(而非工作表模块)?
Have you tried moving your function to a regular module in Excel (not a sheet module)?
这篇关于从.NET中的VBA函数访问返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!