Frage

I'm using Delphi 2007's ExcelXP components as explained here to connect to MS Excel and populate some fields in a worksheet. That works as it should, I can modify the worksheet all I want.

However, I want Excel to stay open after the application ends, but only if there is an open worksheet in Excel. I can get the number of opened workbooks with ExcelApplication.Workbooks.Count, so it would be an easy task to check whether any workbooks are opened when the application ends, and to close Excel during the OnDestroy or similar.

Right now I am stuck though in a situation where Excel closes regardless if there are any opened workbooks as soon as my application ends. Not due to any .Disconnector .Quit calls, it still does that when I take them all out; Excel still closes as soon as my application closes.

Does anybody have any idea as to how I can get Excel to stay open if there are open workbooks, and close it when there are none?

Update: The AutoQuit property of my TExcelApplication was set to True. Turns out that was the problem all along.

War es hilfreich?

Lösung

Answering my own question, my coworker noticed that the TExcelApplication component has an AutoQuit property. Set that to False and Excel stays open. Now I can manually quit/disconnect Excel in my OnDestroy events.

Andere Tipps

The following Deborah Pate's page suggests to me that ExcelXP closes Excel automatically if no Delphi object references it. It's not an issue with MS Interop components:

Note, however, that Excel will hang around in memory, running invisibly, unless you've released all your workbook and worksheet variables. Disconnect any components, set any interface variables to nil, and set any variants to Unassigned to prevent this.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top