Some Background/Findings
(see solution below if you don't care about this :) )
For us it happened in code that compiles and runs successful in Excel 2010, 2016 and 2019. So it must be some pretty bad compiled-code processing bug.
Our problem occurs at definite, always reproducible code locations. When one debugs/inspects the variables, strange things happen (other objects shown than expected, visual sections of excel elements get completely white/broken) ... as if it slowly internally crashes before it will disappear automatically (also from task manager) (sometimes without the immediate auto-restart dialog).
Solution (save with uncompiled code)
Our final 6 to 8 step solution is quite simple since it seems to be a bug with the runtime on compiled macro code workbooks that have been saved and opened anew:
- rename the workbook file, e.g.
foo.xlsm
to foo2.xlsm
(untrusted name/file)
- open
foo2.xlsm
and do not enable macros
- open VBE editor (ALT+F11)
- (once/first time per file, e.g.
foo2.xlsm
):
insert some CrashFix
module
- (right click project => insert module)
write or update some only-existing comment line inside, e.g.
'excel crash fix from https://stackoverflow.com/a/59876944/1915920: 2020-01-23 10:00
- if already existing: just change anything there, e.g. change to current time
- (=> the code, although only changed on comment-level, will be internally marked as uncompiled and will be recompiled on next open with enabled macros)
- close and save
foo2.xlsm
- rename back
foo2.xlsm
to foo.xlsm
- optional: write protect file on file-level
- may be only useful if updates are infrequent
- prevents it from beeing saved accidentially with compiled code causing the crash on next open again
Now you should be able to open it without crashing (since obviously the initial compile run on startup prevents the crash somehow).
For others using the file (e.g. in a network share environment) it should now open without any macro-enable dialog. (for your own env it may ask again, since Excel "knows" somehow it was renamed inbetween on your system)