Excel Prank - Prevent Closing a Workbook

Add to Favorites

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.


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).

Question? Ask it in our Excel Forum

Downloadable Files: Excel File