Vba turn off alerts in Excel

For example, I have written a macro to automate a set of routine tasks so that no user intervention is required. However, since my automation involves deletion of WorkSheets (so, whenever code is executed to delete

WorkSheet, pop up message "Data may exist in sheet selected�..") as well as file overwriting (pop up message confirming if file can be overwritten), user intervention is required. Is there a way to suppress these messages?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub SubRoutineSample()
  3. Application.DisplayAlerts = False
  4. ' complex
  5. ' macro
  6. ' function
  7. ' goes here
  8. Application.DisplayAlerts = True
  9. End Sub

Description:

a) Line 3 - Turn OFF Display Alerts when macro is running. This suppresses pop ups. This can be placed at the beginning of code or just before actions that induce pop up messages like WorkSheet deletion, file save etc.,

c) Line 8 - Turn ON Display Alerts after macro is executed.

 

You can find similar Excel Questions and Answer hereunder

1) Userform initialize vs userform show in Excel

2) Vba to return week numbers in Excel

3) How to create Pivot table in excel VBA

4) How can I hide all comments in my WorkSheet using VBA?

5) Vba code to password protect workbook in Excel

6) How can I update a listbox based on data in a list using VBA?

7) How can I change the Marker size and Marker line color for all the series in a chart?

8) How can I list all files in a folder using VBA?

9) How do I add a symbol like Triangle / Inverted Triangle for indicating trends in a cell using VBA?

10) How to delete rows with Excel VBA

 

Here the previous and next chapter