rishaan
asked on
How to invoke macro from .net
Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
oExcel.Visible = true;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel._Workbook oBook = null;
oBook = oBooks.Open("C:\\Test.xls" , oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
// Run the macros.
RunMacro(oExcel, new Object[] { "Module1.Macrox" });
// Quit Excel and clean up.
oBook.Close(false, oMissing, oMissing);
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oBook);
oBook = null;
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oBooks);
oBooks = null;
oExcel.Quit();
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oExcel);
oExcel = null;
[b]Getting error----
1Exception has been thrown by the target of an invocation.[/b]
oExcel.Visible = true;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel._Workbook oBook = null;
oBook = oBooks.Open("C:\\Test.xls"
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
// Run the macros.
RunMacro(oExcel, new Object[] { "Module1.Macrox" });
// Quit Excel and clean up.
oBook.Close(false, oMissing, oMissing);
System.Runtime.InteropServ
oBook = null;
System.Runtime.InteropServ
oBooks = null;
oExcel.Quit();
System.Runtime.InteropServ
oExcel = null;
[b]Getting error----
1Exception has been thrown by the target of an invocation.[/b]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.