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 .Disconnect
or .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.
AutoQuit
property of my TExcelApplication was set toTrue
, I updated my question accordingly. Silly mistake from my side. Not deleting the question though, in case somebody has the same problem, I know I could have made use of it. – Felix R