1

I have already had several cases of Excel crashing.

The starting point is that an Office addin is currently busy with longer lasting actions (searching for functions across all sheets with subsequent retrieval of data from the server and subsequent writing of this data to Excel). If you click into a cell during this time and enter a value, you will get an "InvalidOperationInCellEditMode", if you are currently working in an Excel.run(asyn context ... - range in the addin. The crash of Excel does not always occur, sometimes it takes dozens of times.

However, such a crash is always annoying for the user who is currently working with the Addin in Excel. By the way, it doesn't help if you catch an Excel.run range, even then Excel crashes.

Marco Siebert
  • 109
  • 10
  • Could you please share the sample code that will crash the excel? it would be nice if you could share the script lab gist, therefore we can repro in our side. – Raymond Lu Apr 30 '20 at 09:15
  • Hi Raymond, it is the same code, i posted in https://stackoverflow.com/questions/61465017/office-js-problems-when-addin-is-executed-in-multiple-excel-instances . The only thing I did is to add a catch arround Excel.run(). Then you just need to create a workbook with lets say 100 sheets, each containing an UDF so that the addin runs a little bit longer. As I mentioned, Excel does not crash all the tim but quite often,. – Marco Siebert Apr 30 '20 at 09:21
  • Here is the gist: https://gist.github.com/MSiebert77/c1417541e0bdb23a035bb8e26f6a5803 – Marco Siebert Apr 30 '20 at 09:24
  • i just tried on this gist, but i am not be able to repro the issue. any tips to repro the crashes? – Raymond Lu Apr 30 '20 at 09:48
  • This issue does not happen all the time, I needed 10+ tries to get it. If you click run, enter a value to a cell while runtime. If you see the exception without crashing in about 5 seconds, you have to click run again for the second try. I just tried it, on the 11th try Excel crashed. Btw.: do you have 100 sheets with functions so the addin runs longer and is not finished before you enter a value? – Marco Siebert Apr 30 '20 at 09:52

1 Answers1

1

The fact that edit-mode makes any API call fail is a "known-issue", and is not really fixable -- even VBA exhibits that same problem for [most] of API calls. and most actions in the ribbon are disabled. So does Office Add-in APIs.

Therefore when entering cell edit mode, API call fail and throw exception InvalidOperationInCellEditMode is by design

There is a workaround not sure if you could leverage in your scenario:

Excel.run has an overload that takes in a RunOptions object. This contains a set of properties that affect platform behavior when the function runs. there is a property: delayForCellEdit Determines whether Excel delays the batch request until the user exits cell edit mode. When true, the batch request is delayed and runs when the user exits cell edit mode. When false, the batch request automatically fails if the user is in cell edit mode (causing an error to reach the user). The default behavior with no delayForCellEdit property specified is equivalent to when it is false.

You can refer to this article: https://learn.microsoft.com/en-us/javascript/api/excel/excel.runoptions?view=excel-js-preview#delayforcelledit

For the Crash issue, I actually not be able to repro it. it would be great if you could share more tips on repro information, thanks.

Raymond Lu
  • 2,178
  • 1
  • 6
  • 19
  • Okay I will see next week. But it surely crashes with that gist. The exception is not a problem but the crash. Maybe I can find some Excel log files. – Marco Siebert May 01 '20 at 05:01
  • I could reproduce the Excel crash and looked into the event log. There I found the following information: – Marco Siebert May 04 '20 at 07:12
  • Name der fehlerhaften Anwendung: EXCEL.EXE, Version: 16.0.11929.20708, Zeitstempel: 0x5e865a93 Name des fehlerhaften Moduls: EXCEL.EXE, Version: 16.0.11929.20708, Zeitstempel: 0x5e865a93 Ausnahmecode: 0xc0000005 Fehleroffset: 0x000000000001d142 ID des fehlerhaften Prozesses: 0xbb0 Startzeit der fehlerhaften Anwendung: 0x01d621e2e9586d43 Pfad der fehlerhaften Anwendung: C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE Pfad des fehlerhaften Moduls: C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE Berichtskennung: 1e068f95-c700-489c-82f8-8e38c05bebc0 – Marco Siebert May 04 '20 at 07:13
  • 1
    DelayForCellEdit helps to avoid Excel crashing but nevertheless you should check why Excel crashes when not using DelayForCelLEdit (see my previous comment for information). – Marco Siebert May 06 '20 at 08:54
  • Yes, the crash should definitely not happen in any situation. As we are not able to repro, we suspect the crash could be tightly related to the workbook. could you please share your workbook that you observe the crash? will you be able to repro with a new workbook? thanks – Raymond Lu May 06 '20 at 09:50
  • It seems not to be an issue of the related workbook. I just started with a new workbook, inserted a SUM-function in sheet1 and afterwards created 25 new sheets and copied the text of that SUM-function into the first cell of each sheet. Than I clicked the run button (of shared gist) and while it was running I entered a value to one cell. Excel crashed immediatelly, I can reproduce it everytime. – Marco Siebert May 06 '20 at 10:20
  • So you repro it in Excel Desktop version? can you repro in other platform? like Mac, excel online? kindly share us the version that crashing the excel – Raymond Lu May 06 '20 at 10:47
  • Yes, I repro it in Excel desktop version. In Excel online I get an exception but no crash. My Excel desktop version was 16.0.11929.20708, I checked for updates and now I got 16.0.11929.20740. But also with that version Excel crashes. Excel online is on version 16.0.12904.35051. – Marco Siebert May 06 '20 at 11:37