How to detect if Excel has a modal dialog open?

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

How to detect if Excel has a modal dialog open?
 
nwein




Posts: 510
Joined: 2011-03-28
The IsEditing solution doesn't work, i.e. Excel's Interactive property is not false when a modal dialog is open. Is there any other way to achieve this?
For Excel 2010 onward.
Posted 23 Aug, 2017 15:34:00 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
Hello Nir,

There's nothing in the Excel object model to solve this task. You can use the Windows API: if the WS_DISABLED style is applied to the main Excel window, this means a modal window is opened. In the case of a dialog built in Excel, you can intercept a Ribbon command opening that dialog window, cancel it and then invoke the same command yourself. this allows you to know when the dialog window is closed. Here's how this approach is described at https://www.add-in-express.com/creating-addins-blog/2011/12/05/excel-calculation-mode-event/ (sample project provided):

That is, the solution includes repurposing a Ribbon control that modifies the calculation mode, cancelling the user action and sending a message to the internal window. When the OnSendMessage event occurs, you filter out “your” message and execute the Ribbon command once again; to avoid getting into a loop, you use a flag.


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Aug, 2017 06:07:39 Top
nwein




Posts: 510
Joined: 2011-03-28
Thanks, the WS_DISABLED is good enough for my purposes. Thanks for getting me on the right track.
Posted 24 Aug, 2017 09:14:03 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
You are always welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Aug, 2017 09:16:37 Top