Turning Off Alerts - Coding Options?

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
Hello all, and TIA.
I have been using #1 below to turn off alerts before deleting a worksheet, but started to get the warning anyway. I found the other methods I've listed below, and think I understand #1 & #2.
#1 is to the worksheet object and will revert to DisplayAlerts = True when the module closes.
#2 is to the workbook object and will remain set until re-set or the workbook is closed.

So #2 is probably my best option for not getting a warning before deleting a worksheet. Because workbook is an object, do I need to reset events for a save as to an .xlsx?

I don't understand what if any difference there is with #3 & #4. And am happy to learn of any others. Can someone please explain what are the differences in these options for turning off Alerts? Possible best practice for this scenario?
  1. VBA Code:
    With Application
          .DisplayAlerts = False
    End With ' Application
  2. VBA Code:
    ThisWorkbook.NoEvents = True
  3. VBA Code:
    xl.DisplayAlerts = False
  4. VBA Code:
    app.DisplayAlerts = False
Again, TIA

Ron
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I'm still curious about #3 & #4, but once again, Chip Pearson to the rescue! Chip also discusses declaring an ". . . App variable (of type Application in the ThisWorkbook code module." I suspect this is what #4 is, but with an assumption the reader would understand "app" was a declaration.

For a different reason, added again earlier today to the comments to Chip's parents. And now another reason. So many "What if's" Chip was still with us.

Event Hierarchy
As noted above, events are generated by:
The Application
The Workbook
The Worksheets
Charts

I don't know the age of the reference I found for ThisWorkbook.NoEvents but it's no longer an Excel event
The proper event code is :
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
Per Chip,
Indeed, this line of code suppresses all events from being raised until its value is reset to True. Note that Excel never automatically sets Application.EnableEvents back to True (as it does do with the ScreenUpdating property). It is up to your code, including well designed error handling code, to ensure that Application.EnableEvents is properly reset to True. See Error Handling In VBA for more information about error handling code.

If interested I invite you to review the source.

Ron
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

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