I’m using Xojo’s Office Automation in Windows, (Excel) and all is well until the spreadsheet I’m working with closes from some exterior influence, ie., user intervention, etc.
Is there a way my Xojo code can detect the Excel application closing?
@Eugene_Dakin is the resident expert this on this. If you don’t already have his book about using Excel with Xojo it is a must have.
I think the automation will throw an error if there is a process currently running updating the spreadsheet but not sure if it is just sitting idle between ops and it closes.
I do not know how to detect if the Excel Application is closing, and I know of a workaround to check if the app is opened or closed, and have attached an example program: ExcelClosed
Open the example program and build an executable. When running the program:
press ‘Check if Excel is closed’ button, and it will show ‘Excel is not open’
Press ‘Open Excel’ button, then press ‘Check if Excel if closed’ button. It will show ‘Excel is open’
Close the Excel app and press ‘Check if Excel if closed’ button. It will show ‘Excel was opened, and is now closed’.
This workaround works on the ActiveWindow caption of the Excel file that is open.
There is a global ExcelApplication variable and code in the Open Excel button is:
Detection code in the ‘Check if Excel is closed’ button is shown below:
You may want to put the detection code on a timer to poll the result occasionally.
Wow! Thanks for the ‘detailed’ explanation @Eugene_Dakin … greatly appreciated!!
As a side, I’d also like to mention how much value your books bring to the subject. I generally don’t read them cover to cover, but more to find a solution to a specific problem. I bought your lastest one (after previously buying the API 1 version) to figure out how to search in Excel. I was pulling my hair out when Xojo threw each time a match couldn’t be found. Then I read the section explaining that this was normal in the debug version and fine in the runtime. Thank you!!