Update: I still don't have a viable solution to this question, new proposals are welcome!
I'm missing an Excel.Application.Quit
or an Excel.Application.BeforeQuit
event. Does anybody know a workaround to mimic these events?
Given an Excel.Application
object (COM Interop in C#), how can I:
- Preferrably prevent Excel from quitting?
- If this is not possible, how can I at least notice when Excel is quit?
Please note: Since I have a COM reference to the Excel.Application
, the Excel process does not exit when Excel is "quit" by the user. Although this sounds contradictory, that's how it is. By "quit" I mean that the user hits "Quit" or the "cross button" at the top right corner of the window. The window closes, the files are unloaded, the add-ins are unloaded and whatever stuff Excel does apart from that which I have no clue of. But I can still use the Application
object to "revive" the process and make Excel visible again, though the add-ins are then missing, and I have no certainty about what else is in an undefined state.
To get rid of this problem, I would like to either Cancel the Quit at the very start (Think of a BeforeQuit
Cancel = true
if it existed), or at least be notified when Excel is quit, so I can release the COM objects and make the process really exit, and next time I need Excel again, I will know that I need to start it up first.
Unfortunately it's a vicious circle: As long as Excel runs, I need the COM objects. So I can't dispose of them before Excel is quit. On the other hand, as long as the COM objects are there, the process doesn't exit even if Excel pretends to quit, so I cannot wait for a process exit event or similar.
I have the unpleasing feeling that I'm going to bash my head against a brick wall...