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:
In one of the subs that runs in between, I have the following code:
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: