CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010

    Excel automation errors from C#

    Hi guys,

    This is my first post, and I'll try to make myself clear.
    I'm trying to launch a macro from a c# program using the following code:


    object oMissing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Excel.ApplicationClass oExcel = null;
    Microsoft.Office.Interop.Excel.Workbooks oBooks = null;
    Microsoft.Office.Interop.Excel._Workbook oBook = null;

    oExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

    oExcel.Visible = true;

    oBooks = oExcel.Workbooks;

    oBook = oBooks.Open(path, false, false,
    oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
    oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

    this.RunMacro(oExcel, new Object[] { "IPReviewPerformStep", stepIndex.ToString(), settings.SAPAPOUserName, settings.SAPAPOPassworde });

    ///////////////// Method to run a macro

    private void RunMacro(object oApp, object[] oRunArgs)
    System.Reflection.BindingFlags.Default |
    null, oApp, oRunArgs);


    So far, I get the following behaviour: The excel file is opened successfully, the macro is launched, but I get automation errors on basic VBA objects like "Application" or "ThisWorkbook" (see error window in attachment).
    However, when I launch the macro from the excel file manually, it works!
    Moreover, I have a similar program launching a macro in another excel file and it works.
    Is it possible that my excel file is corrupted?

    If you have any idea, feel free to help! Thanks
    Attached Images Attached Images  

  2. #2
    Join Date
    Apr 2010

    Re: Excel automation errors from C#

    Is it possible that my excel file was made in a too old version of excel? maybe excel 7.0

    Still can't go any further in that project...

  3. #3
    Join Date
    Apr 2010

    Re: Excel automation errors from C#

    I found out that the max number of arguments when invoking the runmacro method is 10. If you try put more than 10 args, you'll get the same error as mine.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)