Trap a close attempt using "Alt+F4"

Whisperer14

Well-known Member
Joined
Nov 6, 2002
Messages
589
If the Cancel button on a form is pressed I can
1. Disable sheets
2. Save
3. Close the workbook

In an attempt to improve security further I would like to carry out those same 3 actions should the user use Alt+F4 to close the form.

Any ideas? (y)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Whisperer14

Well-known Member
Joined
Nov 6, 2002
Messages
589
Thanks Thomas for the quick response.

The form is the start element of the programme and offers a series of options, the Cancel button has a close programme function.

I need to prevent the programme remaining open if either the 'X' is used on the form or if the user presses Alt+F4, I have resolved the 'X' by having the userform sit on a modeless background form that fills the screen and the only way that it can be closed is from within the VBA or by using Alt + F4.

TheTerminate Event is what I would be using, but I need to trap the Alt+F4 keypress in some way to differentiate between a normal close down of the form that happens once a selection has been made from the form, and an attempt to get at the programme by using Alt+F4 :oops:

Best wishes
Gordon
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,956
Messages
5,856,507
Members
431,819
Latest member
hellosunshine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top