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
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);
... 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
.
Could someone please tell me how to get at the return value of Multiply from my C# code?