Home / Macros / Disable Alerts and Warning Messages in Excel

Disable Alerts and Warning Messages in Excel

When building macros there can be times when the standard Excel warning alerts need to be disabled in order for the macro to complete it’s intended function.

Disable DisplayAlerts Property

An example may be where you have developed a macro that needs to create a temporary worksheet to store some values and then before completing the macro you need to clean-up and delete that sheet. The standard Excel warning alert would be presented unless you include some code to disable that alert.
delete worksheet dialog box

The following macro use the DisplayAlerts Property to temporarily disable Excel’s standard alerts and warning messages.

Step 1

Open the workbook with the hidden worksheets and start the Visual Basic Editor (Alt + F11). Right Click in the project explorer window and select Insert > Module. Copy the following code into the new Module

Public Sub DeleteWorksheet()
	Application.DisplayAlerts = False
	Application.DisplayAlerts = True
End Sub

Step 2

Note : The final step in the macro enables Excel alerts. This is done to ensure any subsequent unplanned actions are reported and handled by Excel.

If you have a question on this post for the Excel Help Desk team or have something you would like to share on this topic then please leave a comment.

About Excel Help Desk

Check Also

CTRL+F1 to Hide the Excel Toolbar using VBA

There are a number of options to solve this problem, the simplest approach we found for this request was the combination of the "SendKeys" function and the Workbook_Activate procedure. Basically we created a routine that would Hide the Toolbar each time the workbook was activated. Then when the workbook was closed or de-activated it would reset the Toolbar to the original state.


  1. This code worked great! I placed the disable code at the start of my macro to disable alerts while the macro runs, and the enable code near the end of the macro to reinstate alerts after the macro was finished.

  2. Similar problem.
    I need to disable the msgbox from cell A1 when i run the macro. however, when i am in the excel sheet and calculate A1 only (using F2+Enter), I need the msgbox to pop-up. (That’s why i cannot just comment out the msgbox alert).
    I tried Application.displayAlert = false
    but it didnt work.

    Can u plz help? thanks

  3. This code close to what i need. I don’t need to delete a sheet but keep the alerts for “This Sheet Only” from displaying. I want to have alerts displayed on other sheets and any other workbooks i may open in the future.

    • Jeremy,
      In order to disable alerts for a specific sheet you would need to place the code on that worksheet…..then depending on what you want to disable the alerts for (ie a specific action, or anything) then you would use a different function on that sheet.
      If you want to send through a sample workbook and also some details we can investigate and respond with a solution….send to support@excelhelpdesk.com
      ExcelHelpDesk Team