This is code which calling Macro but it is taking 15 minute time when i am running the same macro from excel then it is taking 4 minute approx. please guide me how to optimize as a result time can be shorten.
using interop version 15
public static void fn_run_macro(string _macro_path, string brokermodel, string brkSheet, string _macroFor, string _CompSSFile = "", string _Custom = "", string _imageFile = "")
{
try
{
string _path_macro = _macro_path;
string _path = brokermodel;
Excel.Application book = null;
Excel.Workbooks workbooks = null;
Excel.Workbook macroWorkbook = null;
Excel.Workbook destinationWorkbook = null;
string macrofileName = Path.GetFileName(_macro_path);
try
{
book = new Excel.Application();
workbooks = book.Workbooks;
macroWorkbook = workbooks.Open(_path_macro);
destinationWorkbook = workbooks.Open(_path, ReadOnly: false);
book.Run("'" + _macro_path + "'!MyMacroFunction");
workbooks.Close();
macroWorkbook.Close();
destinationWorkbook.Close();
}
catch (Exception ex)
{
// throw ex; // the finally will be executed before this is thrown
}
finally
{
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;
}
}
catch
{
}
}
Calling above function this way
**Util.fn_run_macro(strPreTreatmentPath + "Horizontal CSM 082113b.xlsm", strTempPreTreatmentPath + "RVNC 01-28-2021 Pre Q4 Update.xlsx", "", "2010AFY");**
Please guide me any other free library available which can call macro and take less time. Thanks