I have a VB Script Macro used in excel File and its works well (Manual). I am trying to convert it to small APP using:
private static void RunMacro()
{
Excel.Application book = null;
Excel.Workbooks workbooks = null;
Excel.Workbook macroWorkbook = null;
Excel.Workbook destinationWorkbook = null;
try
{
book = new Excel.Application();
workbooks = book.Workbooks;
macroWorkbook = workbooks.Open(System.Windows.Forms.Application.StartupPath + "\\NewMacro.xltm");
destinationWorkbook = workbooks.Open(System.Windows.Forms.Application.StartupPath + "\\TEST.csv");
book.Run("NewMacro.xltm");
macroWorkbook.Close(false);
destinationWorkbook.Close(true);
}
catch (Exception ex)
{
throw ex; // the finally will be executed before this is thrown
}
finally
{
book.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(macroWorkbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(destinationWorkbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
macroWorkbook = null;
destinationWorkbook = null;
workbooks = null;
book = null;
}
}
I get the following error:
Additional information: Cannot run the macro 'NewMacro.xltm'. The macro may not be available in this workbook or all macros may be disabled.