14. VBA Tips - Turn Off Message Boxes Whilst Running Code
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
- 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:
The first sub will run displaying the message box, the second one will not.
Training Video on how to Turn Off Message Boxes Whilst Running Code in Excel: