14. VBA Tips - Turn Off Message Boxes Whilst Running Code

Nick's picture


There are certain message boxes that will popup by default when you're running code.

  • An example of this is the alert that asks you if you are sure you want to delete a sheet

turn-off-message-boxes-whilst-running-code

  • If you don't want these alerts to pop up when you're running code, you can turn them off
  • Use:  Application.DisplayAlerts = false at the beginning of the code
  • Don't forget to turn them back on at all exit points of the code otherwise you might permanently delete a sheet by accident
  • To turn them back on, use: Application.DisplayAlerts = true

Here's a screen shot of our code:

turn-off-message-boxes-whilst-running-code

The first sub will run displaying the message box, the second one will not.

Download sheet to practise how to Turn Off Message Boxes Whilst Running Code in Excel

Training Video on how to Turn Off Message Boxes Whilst Running Code in Excel:

AttachmentSize
turn-off-message-boxes-whilst-running-code.xls35 KB

This code is good

Thanks for your support. The code really worked for me.

Simillar issue is not being solved.

I have followed the same code, but the issue for my worksheet has not been resolved. Can anyone help me.