I call a function right at the start of my code that looks like this:
Sub OptimizeCode_Begin() Application.ScreenUpdating = False EventState = Application.EnableEvents Application.EnableEvents = False CalcState = Application.Calculation Application.Calculation = xlCalculationManual PageBreakState = ActiveSheet.DisplayPageBreaks ActiveSheet.DisplayPageBreaks = False End Sub
At the end of my code I call:
Sub OptimizeCode_End() ActiveSheet.DisplayPageBreaks = PageBreakState Application.Calculation = CalcState Application.EnableEvents = EventState Application.ScreenUpdating = True End Sub
In one of the subs that runs in between, I have the following code:
If .Worksheets(intCount).Name = "Invoice" Then Worksheets("Invoice").Delete .Worksheets.Add With ActiveSheet .Name = "Invoice" End With booFound = True Exit For End If
Yet for some reason, at the line:
I still get the warning about deleting a sheet.
If I change that block above to:
If .Worksheets(intCount).Name = "Invoice" Then Application.DisplayAlerts = False Worksheets("Invoice").Delete Application.DisplayAlerts = True .Worksheets.Add With ActiveSheet .Name = "Invoice" End With booFound = True Exit For End If
It works fine. But my question is why do I need the "Application.DisplayAlerts = False" immediately before the .Delete statement? Surely alerts should already be set to False due to the initial sub setting it that way?
Also posted here: