Display Alerts

It can be annoying to have to respond to system alerts while a macro runs. For example, if a macro deletes a worksheet, an alert message appears and you have to click the OK button to continue. However, there is also the possibility of a user clicking the Cancel button, which would abort the delete operation and could adversely affect subsequent code where the delete operation was assumed to have been carried out.

You can suppress most alerts by setting the DisplayAlerts property to False. When you suppress an alert dialog box, the action that is associated with the default button in that box is automatically carried out, as follows:

Application.DisplayAlerts = False ActiveSheet.Delete Application.DisplayAlerts = True

It is not necessary to reset DisplayAlerts to True at the end of your macro because VBA does this automatically. However, it is usually a good idea, after suppressing a particular message, to turn the alerts back on so that any unexpected warnings do appear on screen.

DisplayAlerts is commonly used to suppress the warning that you are about to overwrite an existing file using File O SaveAs. When you suppress this warning, the default action is taken and the file is overwritten without interrupting the macro.

Was this article helpful?

0 0
The Accidental Blogging Millionaires

The Accidental Blogging Millionaires

Get Inspired By The Most Popular Bloggers Online! If You Want To Skyrocket Your Success With Business And Improve Your Overall Life You Need To Have A Look At The Accidental Blogging Millionaires! Business can be a fight, particularly when you’re trying to establish one online and like all fights, to succeed you must find the winning techniques and apply them.

Get My Free Ebook

Post a comment