Blocking dialogs in Excel

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

Blocking dialogs in Excel
 
OliverM




Posts: 144
Joined: 2015-08-13
Is there a way determine when a blocking dialog like 'Want do save changes to Book1?' closes?
Kind regards
Oliver
Posted 11 Nov, 2016 10:18:01 Top
Andrei Smolin


Add-in Express team


Posts: 14094
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 How to create a custom event when Excel calculation mode changes. 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 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).

Regards from Belarus (GMT+3),

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




Posts: 144
Joined: 2015-08-13
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.
Kind regards
Oliver
Posted 11 Nov, 2016 11:25:47 Top
Andrei Smolin


Add-in Express team


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

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

Regards from Belarus (GMT+3),

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




Posts: 144
Joined: 2015-08-13
Hi Andrei,

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


Add-in Express team


Posts: 14094
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.

Regards from Belarus (GMT+3),

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




Posts: 144
Joined: 2015-08-13
Thank you Andrei,

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


Add-in Express team


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

Regards from Belarus (GMT+3),

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