Blocking dialogs in Excel

Add-in Express™ Support Service
That's what is more important than anything else

Blocking dialogs in Excel
 
OliverM


Guest


Is there a way determine when a blocking dialog like 'Want do save changes to Book1?' closes?
Posted 11 Nov, 2016 10:18:01 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Oliver,

Could you please explain your goal? Who initiates this dialog? User action? Your code? What will you do next?

If this is the user who initiates the dialog by clicking a built-in Ribbon control or pressing a key combination, you can intercept that control and that key combination. In the code of the event handler(s), you perform the action that may show the dialog; your code executing after the action is called will be executed immediately after the dialog closes.

This idea is implemented in https://www.add-in-express.com/creating-addins-blog/2011/12/05/excel-calculation-mode-event/. The idea is this:
- you use a ADXRibbonCommand component to intercept invoking a Ribbon control,
- when the built-in control is invoked and the component raises the corresponding event, you cancel the operation, and use the SendMessage/OnSendMessage machinery described in https://www.add-in-express.com/docs/net-office-tips.php#wait-a-little to perform the same action programmatically; in that case it was showing a dialog box. This time the action execution is wrapped in your code; your code is executed immediately after the action is completed.

Also I would check if Commandbars.OnUpdate event occurs right after the dialog closes. In Add-in Express this event is mapped to the CommandbarsUpdate event of the Excel Events component (ADXExcelAppEvents).


Andrei Smolin
Add-in Express Team Leader
Posted 11 Nov, 2016 10:40:28 Top
OliverM


Guest


Hi Andrei,

Queston is related to the following scenario: Backgroundworkers are assigned to every opened workbook in my application. If the user decides to close a book the workers need to be stopped and a cleanup procedure runs.
I currently achieve this by consuming the Workbook_BeforeClose event. All is fine if the user really closes the book but if he decides to cancel closing the issue arises how to restart the workers.
If I could consume some kind of 'UserDidNotCancelClose' event, I would be able to change my process to only stop workers if this event is fired.
Posted 11 Nov, 2016 11:25:47 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Oliver,

You can use the CommandbarsUpdate event to find whether the workbook gets closed or not.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2016 05:25:11 Top
OliverM


Guest


Hi Andrei,

Do you have an example how to achieve that?
Posted 14 Nov, 2016 08:55:40 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
No, we don't have such an example.

You can compare the workbooks opened now and on the previous run of the CommandbarsUpdate event.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2016 09:11:41 Top
OliverM


Guest


Thank you Andrei,

I give it a go.
Posted 15 Nov, 2016 05:00:28 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 15 Nov, 2016 05:32:20 Top