locked
com interop opens XLSM file in Excel 2003 RRS feed

  • Question

  • I have a windows form app that uses interop to automate excel tasks. The version of the interop referenced in my project is 12.0.0.0. I execute code similar to the following to open an XLSM file:

    excelApplication = new Microsoft.Office.Interop.Excel.Application();
    excelApplication.Visible = ExcelVisibleCheckBox.Checked;
    wb = excelApplication.Workbooks.Open(modelPath, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value,
    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
    Missing.Value, Missing.Value);

    (where modelPath is an XLSM file)

    Yet instead of opening Excel 2007 it opens Excel 2003 and starts to convert the file. It is necessary for me to have both Excel 2003 and 2007 on my machine and the XLSM file should open in Excel 2007.

    Any ideas?

    Thanks in advance

    Doug
    Monday, November 9, 2009 2:12 AM

Answers

  • Hello Doug

    To explicitly specify the version of Excel to be started, instead of calling "new Excel.Application", please use this code:

    Type t = Type.GetTypeFromProgID("Excel.Application.12");
    Excel.Application oXL = (Excel.Application)Activator.CreateInstance(t);

    If you have any other questions, please feel free to tell me.

    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, November 9, 2009 9:41 AM

All replies