Hi Friends,
I need to run excel macro multiple time with some changes in the input. since macro takes more time to execute i need to open multiple instance of excel and run macros parallely. How can i achieve this? please help me with some ideas.
Current timing
one macro run will take ~10 mint. i need to call this macro in a loop with count 25.so approx it taking 2hrs. my aim is to reduce to 30 mint
public static Excel.Application oExcel;
oExcel = new Excel.Application();
object oMissing = System.Reflection.Missing.Value;
oExcel.Visible = false;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel.Workbook oBook = null;
oBook = oBooks.Open(filepath, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
for (int i = 0; i < 25; i++)
{
Excel.Worksheet sheet = (Excel.Worksheet)oExcel.Sheets[1];
sheet.Cells[8, 3] = i;
MacroRun.RunExcelMacro(oExcel, "runTestCases");
}
What I have tried:
private static void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember(Constants.RUN,
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}
public static void RunExcelMacro(Excel.Application oExcel, string macroname, string paramaters = "")
{
if (paramaters == "")
RunMacro(oExcel, new Object[] { macroname });
else
RunMacro(oExcel, new Object[] { macroname, paramaters });
}