DisplayAlerts

peterbata

New Member
Joined
Feb 20, 2016
Messages
20
Hello and thank you for taking my inquiry.

I am learning about VBA code and am wondering why when stepping through these lines of code I am not presented with a warning prompt. It executes successfully but no warning. The sheet is deleted.

Sub DeleteSpecificSheets()


Application.DisplayAlerts = False
Worksheets("sheet8").Delete
Application.DisplayAlerts = True


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Well that makes two of us.



Does this mean 3 new sheets within the current workbook or an entirely new workbook and the same strange behavior exists?
I am experiencing the same behavior with existing and new worksheets. Regardless of what I try, the result is the same.

I thought that perhaps it might be a global setting in Excel, but I wouldn't know ehere to start looking. Thanks for all of your time and effort. Back to the drawing board. One thing that I will do is move to another PC and duplicate the process.
 
Upvote 0
I am experiencing the same behavior with existing and new worksheets. Regardless of what I try, the result is the same.

I thought that perhaps it might be a global setting in Excel, but I wouldn't know ehere to start looking. Thanks for all of your time and effort. Back to the drawing board. One thing that I will do is move to another PC and duplicate the process.
I suspect it will be because alerts had already been disabled and not turned back on.

Try running this code by itself first:

Rich (BB code):
Sub TurnAlertsOn()
Application.EnableAlerts = True
End Sub

Then try your code:

Rich (BB code):
Sub DeleteSpecificSheets()
Worksheets("sheet7").Delete
End Sub
 
Last edited:
Upvote 0
I suspect it will be because alerts had already been disabled and not turned back on.

Try running this code by itself first:

Code:
Sub TurnAlertsOn()
Application.EnableAlerts = True
End Sub

Thanks Fishboy, but is it possible you meant

Code:
Application.EnableEvents = True

You can do this in the Immediate window also just like before
 
Last edited:
Upvote 0
Thanks for chiming in Fishboy. Really appreciate it. Did exactly what you suggested in a new worksheet. Exact same result. I see no pop-up alert at all. The sheet is deleted outright. Here is what I am going to do right now. Log in remotely to one of my clients PC. They are running Excel 2013. I will give that a go and post back.
 
Last edited:
Upvote 0
Try running this code by itself first:

Code:
Sub TurnAlertsOn()
Application.EnableAlerts = True
End Sub

Thanks Fishboy, but is it possible you meant

Code:
Application.EnableEvents = True

You can do this in the Immediate window also just like before


No. I am sure he meant EnableAlerts

EnableEvents means things like selection change, calculate, activate window

EnableAlerts means the alerts like "Do you want to save before you Exit?"
 
Upvote 0
Yes Jeffrey I caught that too. Used "Application.EnableEvents = True" in the Immediate console as you suggested. No change unfortunately!
 
Upvote 0

Forum statistics

Threads
1,216,297
Messages
6,129,954
Members
449,544
Latest member
Akhil333

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top