We are in the process of updating the site, so some pages still have the older design.

Excel Prank - Prevent Closing a Workbook

Download Project Files
Author:

How to prevent a user from closing an Excel workbook. The user won't know what to do!

This is a great little prank that will leave your co-worker confused and annoyed. Use with caution ;)

To make this work, you will have to install a small macro and make sure the workbook has macros enabled by default.

  1. Hit Alt + F11 to go to the VBA Editor.
  2. Double-click ThisWorkbook

  3. In the window that opens click the left drop-down menu and select Workbook.
  4. Some default text will appear, don't worry about that, just delete it.
    Then go to the drop-down menu on the right and select BeforeClose

    More text should have appeared and it should now look like this:
  5. In the middle type Cancel = True

  6. Go back to Excel (hit Alt + F11) and try to close the window.
    As long at the workbook has macros enabled, the user will not be able to close the workbook. Clicking the X in the upper right hand corner will not work and neither will clicking Close from the menu.

This is a particularly evil prank because the user will have no idea what is going on unless they are well versed in macros.

Notes

It's your fault if your co-worker goes postal! :P

Download the file attached to this tutorial to try this out. It will only work if you enable macros and you uncomment the single line of code in it (I had to comment-out the code so I could close it on my computer).

Download the Project Files

Follow along with the tutorial by downloading the files used in it. (Completely Free)

Phone number is optional - we use it to send course discounts and weekly updates via SMS.

SMS Terms ▾
By submitting this form, you agree to receive recurring automated marketing text messages from TeachExcel at the mobile number provided. Consent is not a condition of any purchase. Msg frequency varies. Msg & data rates may apply. Reply HELP for help or STOP to cancel at any time.

View our Privacy Policy | Terms of Use

Downloadable Files: Project File

Download Project File

Follow along with the tutorial by downloading the files used in it. (Completely Free)

Phone number is optional - we use it to send course discounts and weekly updates via SMS.

SMS Terms ▾
By submitting this form, you agree to receive recurring automated marketing text messages from TeachExcel at the mobile number provided. Consent is not a condition of any purchase. Msg frequency varies. Msg & data rates may apply. Reply HELP for help or STOP to cancel at any time.

View our Privacy Policy | Terms of Use

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Tutorial Details
Downloadable Files: Project File

Download Project File

Follow along with the tutorial by downloading the files used in it. (Completely Free)

Phone number is optional - we use it to send course discounts and weekly updates via SMS.

SMS Terms ▾
By submitting this form, you agree to receive recurring automated marketing text messages from TeachExcel at the mobile number provided. Consent is not a condition of any purchase. Msg frequency varies. Msg & data rates may apply. Reply HELP for help or STOP to cancel at any time.

View our Privacy Policy | Terms of Use
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course