Dear Friends,
While automating in Excel through Excel VBA, you may want to delete or add some Worksheets. This is a very common task, which we try to do. I have already written an article where I have explained a lot about deleting worksheets using Excel VBA.
In this article, I am going to teach you all about disabling the warning message while deleting a sheet using Excel VBA.
While deleting a sheet from excel workbook, you get a warning message like shown in below image. This is a built-in warning message.
This warning message is shown in both the case : Either you delete a sheet manually or VBA trying to delete a sheet.

Delete-Warning-Message

Delete-Warning-Message


During VBA code execution, if you do not disable this notification, your program will wait until you press OK on this notification. Which is really not something you want.
So, the question is how to disable this sheet delete notification using VBA.

Solution: There is a very easy solution for this. All you need to do is – set Application.DisplayAlerts = False before deleting the sheet.
refer the below code:


Private Sub DisableWarningMessage()

'---  disable all types of Alerts from Excel like while deleting the Sheet etc.
Application.DisplayAlerts =False
'--- Now delete the particular Sheet
Worksheets("Sheet2").delete
'--- Again enable the alerts
Application.DisplayAlerts = True
End Sub

Note: After deleting make sure that we are again setting the Application.DisplayAlerts as True. Otherwise, even if we are deleting any sheet from any of the Excel Sheet in your PC, no Alert will appear. So always disable it before deleting and then again enable it back after deletion.

To know more about deleting sheets, refer these articles:

cover3d_0-89071700_1484285537__1_

Join over 10, 000+ Excel VBA Enthusiasts & get this FREE e-Book Now!