how to catch these events?
-
Can we catch(or overload the event handler) the (Yes, No, Cancel) button click events of Microsoft Excel when the user clicks the Close(X) button on the top right corner of the ms excel workbook? Am basically building an excel automation add-in to ms excel using c#.
-
Can we catch(or overload the event handler) the (Yes, No, Cancel) button click events of Microsoft Excel when the user clicks the Close(X) button on the top right corner of the ms excel workbook? Am basically building an excel automation add-in to ms excel using c#.
Excel isn't written in C#, and you can't just hook into the code like you would with something that you have written yourself. You can hook into native code, you can get the handle of the buttons of the closedialog and send a click-message, but I don't know if it is possible to hook into the WndProc of Excel. This is not a simple assignment for the weekend!
I are troll :)
-
Excel isn't written in C#, and you can't just hook into the code like you would with something that you have written yourself. You can hook into native code, you can get the handle of the buttons of the closedialog and send a click-message, but I don't know if it is possible to hook into the WndProc of Excel. This is not a simple assignment for the weekend!
I are troll :)
hey Eddy, thanks for replying. I've been scratching my head since... Basically, I want to create an xml for every excel sheet the user saves and when he reopens the excel sheet, I am supposed to open the corresponding xml. Thus, I used the WorkbookBeforeClose http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook_events(VS.80).aspx[^]event and my whole aim is achieved if *the user is saving the sheet first and then closing ms excel* However, the problem is, when he is trying to save the sheet by: Press the Close(X) button and when the pop up which says "Do you want to save changes to filename.xls? 'Yes' 'No' 'Cancel'" shoots up and IF he is choosing 'Yes' here, am not able to achieve the same. The reason being, the WorkbookBeforeClose event is invoked as soon as he presses the Close(X) button on the top right corner of ms excel. I want to somehow be able to know whether the user has chosen 'Yes' or 'No' from the pop-up. Can I?! If yes, kindly tell me how?! Regards.
-
hey Eddy, thanks for replying. I've been scratching my head since... Basically, I want to create an xml for every excel sheet the user saves and when he reopens the excel sheet, I am supposed to open the corresponding xml. Thus, I used the WorkbookBeforeClose http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook_events(VS.80).aspx[^]event and my whole aim is achieved if *the user is saving the sheet first and then closing ms excel* However, the problem is, when he is trying to save the sheet by: Press the Close(X) button and when the pop up which says "Do you want to save changes to filename.xls? 'Yes' 'No' 'Cancel'" shoots up and IF he is choosing 'Yes' here, am not able to achieve the same. The reason being, the WorkbookBeforeClose event is invoked as soon as he presses the Close(X) button on the top right corner of ms excel. I want to somehow be able to know whether the user has chosen 'Yes' or 'No' from the pop-up. Can I?! If yes, kindly tell me how?! Regards.
I'm no expert on Excel-interop, but I'm sure that some of those hang round here. In the meantime, there are two interesting events in that same documentation; -
BeforeSave
I guess this one is also fired if the user chooses "Yes", but not if he chooses "Cancel" or "No". -ShutDown
Signals that the application is about to shut down. Perhaps you could do the same with aFileSystemWatcher
, watching all the XLS-files in the specified directories for updates. Anyone else any idea's?I are troll :)