none
Excel 2013 macro compatibility issue due to SDI RRS feed

  • Question

  • Excel 2013 is now SDI. If I have a macro that needs to open a separate instance of Excel to kick off a long calculation, the following code no longer opens the file in a separate instance:

    Dim xl As Application

    Set xl = New Application

    I tried spawning a new process using excel.exe /X, but this has the unfortunate effect of causing strange  COM Exceptions HRESULT 800AC472 when writing to certain cell values. I need a reliable method to open a separate excel instance programmatically, as 2013 has essentially broken compatibility with many macros by trying to share instances.

    Thanks

    Thursday, February 26, 2015 12:13 AM

All replies

  • I tried spawning a new process using excel.exe /X, but this has the unfortunate effect of causing strange  COM Exceptions HRESULT 800AC472 when writing to certain cell values.

    Hi DeltaEpsilon,

    How did you do in your code to call the command "excel.exe /X" and write value to a certain cell? Could you please post the complete code here?

    In ordinary circumstances, this error means that the Excel application is busy on something and the user is not supposed to do anything at this time. I guess you access to the cell value immediately when after you call the command, the other instance is actually not ready at this time. You can use Application.Ready to determine if we can write to the cells.

    If Application.Ready = True Then 
    	'Write value to cells
    End If 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, February 27, 2015 6:26 AM
    Moderator
  • I'm actually doing the spawning from our Addin Express addin using this code:

    public static void OpenExcelFileInNewInstance(Application excelApp, string filePath)
            {
                var ver = Microsoft.VisualBasic.Conversion.Val(excelApp.Version);
                var excelPath = excelApp.Path._PathCombine("excel.exe");
                
                if (ver > 14) //2013 or newer needs /X param for separate instance
                {
                    Process.Start(excelPath, " /X \"" + filePath+"\"");
                }
                else
                {
                    Process.Start(excelPath, "\""+filePath+"\"");
                }
            }

    When spawning new excel processes using this method it seems excel does not become ready until the user interface has been manually clicked.

    The fact remains however, that there is no longer a way to open a separate instance of excel using VBA automation due to this SDI "upgrade" in 2013.


    Monday, March 2, 2015 6:54 PM
  • When spawning new excel processes using this method it seems excel does not become ready until the user interface has been manually clicked.

    Then you can try to activate the workbook or call the SetFocus function:

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms646312(v=vs.85).aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 9, 2015 5:55 AM
    Moderator