Delete Sheet In VBA Without Notification

.

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:

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

How to Copy content from Word using VBA

As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

1 Comment

  1. Vishwamitra Mishra

    Note: This alert is not only for deleting sheet, but it applies on all the Excel Specific Errors. Though error is coming from Excel, but still it will not be shown to the user, on disbaling this Alert Falg.

    Reply

Trackbacks/Pingbacks

  1. 40 Useful Excel Macro [VBA] examples - Part 1 of 2 - Let's excel in Excel - […] Note: If you do not enable the Application.DisplayAlert flag after deleting your sheet then you would not even get…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest