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]
rishaanAsked:
Who is Participating?
 
anarki_jimbelCommented:
First, this may help:

http://support.microsoft.com/kb/306683

2. When showing errors - try to show stack trace and error text. Hard to say without seen details
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.