Link to home
Start Free TrialLog in
Avatar of rishaan
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.InteropServices.Marshal.ReleaseComObject(oBook);
                    oBook = null;
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
                    oBooks = null;
                    oExcel.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
                    oExcel = null;
[b]Getting error----
1Exception has been thrown by the target of an invocation.[/b]
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial