PDA

View Full Version : Can I "cancel" Workbook_WindowDeactivate?



TheAntiGates
12-07-2016, 04:12 AM
Background, I wanted to set a personal.xls event to catch when I closed one of those multi-windows with a colon (e.g. Book1:1), catching Control-F4. Worksheet_deactivate and workbook_sheetDeactivate don't work for this, or even Workbook_Deactivate. But, yay, there's Workbook_WindowDeactivate(ByVal Wn As Excel.Window) which reacts to Control-F4. So let's say I Control-F4 Book1:1, and I want to cancel the closing if certain tests are met.

Unfortunately in each of these the close happens anyway :(
- alt-R,R (run/reset) in VBA window if code is stopped
- msgbox, control break, and then click End on the dialog.
- an End statement (one word command, End).
Note, one might consider Quit as the next "stronger" halt statement but that's too drastic.

Is there a way to cancel the window closing? Obviously they don't provide a Cancel parameter but I'm hoping against hope. Maybe using some other event? .OnWindow?