How to Disable Alerts in Excel VBA: 3 Methods

Method 1 – Open Visual Basic Editor

  • Go to the Developer tab >> click the Visual Basic button.

Open Visual Basic Editor

This opens the Visual Basic Editor in a new window.

Method 2 – Insert VBA Code

  • Go to the Insert tab >> Select Module.

Insert VBA Code

For ease of reference, copy the code from here and paste it into the window below.

Option Explicit

Sub Delete_worksheet()
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True
    MsgBox "Macro Executed Successfully!"

End Sub

VBA code for excel vba disable alerts

Code Breakdown:

We’ll explain the VBA code used to disable alerts. The code is divided into 2 steps.

  • The sub-routine is given a name; here, it is Delete_worksheet().
  • Set the Application.DisplayAlerts property to the Boolean value of False.
  • Apply the Worksheets. Delete method to remove the specified worksheet.
  • Invoke the Application. Display Alerts property, but this time, set it to True to ensure the code runs smoothly.
  • Use the MsgBox function to prompt the message that the code ran successfully.

Code breakdown

Method 3 – Run the VBA Code

Tthe VBA code removes the “Sheet4(Temp)” worksheet in the image below.

Running VBA Code to delete specific worksheet

  • Click Run or press the F5 key to run the macro, as shown in the GIF below.

Running the macro and showing results

The “Temp” worksheet is removed.

Removed worksheet

How to Enable Alerts in Excel VBA

Enable the alerts in Excel VBA by changing the DisplayAlerts property Boolean value to True.


  • Follow Steps 1-2 from the previous method to open the Visual Basic editor, insert a new Module and enter the code.

The VBA code is almost the same, except for the Application.DisplayAlerts property, which has been set to True.

Option Explicit

Sub Delete_worksheet_with_alert()
    Application.DisplayAlerts = True
    MsgBox "Macro Executed Successfully!"

End Sub

How to Display Alerts in Excel VBA

  • Hit Run >> to execute the Delete_worksheet_with_alert macro >> a warning pops out asking for the confirmation of the deletion >> Press Delete to execute the macro successfully.

Steps to enable alerts in VBA

Things to Remember

  • Enter the name of the worksheet you want to delete, in this case, the “Temp” worksheet.

Things to Remember entering correct sheet name

  • If the worksheet does not exist, then you’ll encounter an error message.

Error running VBA code

Download Practice Workbook

Related Articles

<< Go Back to Alerts in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Eshrak Kader
Eshrak Kader

Eshrak Kader is a dedicated professional with a BSc. Degree in Naval Architecture and Marine Engineering from Bangladesh University of Engineering and Technology. He boasts a rich background in Microsoft Office Suite, and over the past year, he has authored over 120 insightful articles for the ExcelDemy. Currently, Eshrak leads a team of 5 in the ExcelDemy Video project and enjoys problem-solving and making videos on Excel. Eshrak’s passion for continuous learning underscores his commitment to excellence in... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF