I'm attempting to run excel vba macro and get back result but I'm always getting back null (excuse my ignorance, I'm new to this macros)
the macro
Public Function TestMacro() As Boolean
If Len(Range("A1").Value) <> 9 Then
TestMacro = False
Else
TestMacro = True
End If
End Function
the c# code invoking it
Excel.Application excelApp = new Excel.Application { DisplayAlerts = false };
object misValue = Missing.Value;
excelApp.Visible = false;
Excel.Workbook ExcelWorkBook = excelApp.Workbooks.Open(filePath);
try
{
var result = excelApp.Run("Sheet1.TestMacro");
ExcelWorkBook.Close(false, misValue, misValue);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
excelApp.Quit();
if (ExcelWorkBook != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelWorkBook); }
if (excelApp != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); }
}