In trying to delete a sheet, I constantly get run-time error 9. I think the reason is because the code called to delete the sheet originates from within a button on the sheet; kinda-sorta like suicide prevention.
To Try to avoid this, I placed code in the activate event of another sheet and created a separate module with code to delete the sheet. However, this still generates the same error.
Any suggestions would be helpful.
Thx,
Mike
Code in the activate event of a sheet:
If ActiveSheet.Name <> "Sand Box" Then
If DelSheet = True Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
On Error Resume Next
Application.DisplayAlerts = False
Call DeleteSheet(SheetToDelete)
'Sheets(SheetToDelete).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
DelSheet = False
SheetToDelete = ""
Sheets("Sand Box").Visible = False
Else
'Do Nothing
'Sheets("Sand Box").Visible = False
End If
Else
End If
Code in
Sub DeleteSheet(strSheetName As String)
'On Error GoTo 0
'Application.DisplayAlerts = False
'Sheets(strSheetName).Select
Sheets(strSheetName).Delete
'ActiveWindow.SelectedSheets.Delete
'ActiveSheet.Select
'Range("A10").Select
'Application.DisplayAlerts = True
End Sub
To Try to avoid this, I placed code in the activate event of another sheet and created a separate module with code to delete the sheet. However, this still generates the same error.
Any suggestions would be helpful.
Thx,
Mike
Code in the activate event of a sheet:
If ActiveSheet.Name <> "Sand Box" Then
If DelSheet = True Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
On Error Resume Next
Application.DisplayAlerts = False
Call DeleteSheet(SheetToDelete)
'Sheets(SheetToDelete).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
DelSheet = False
SheetToDelete = ""
Sheets("Sand Box").Visible = False
Else
'Do Nothing
'Sheets("Sand Box").Visible = False
End If
Else
End If
Code in
Sub DeleteSheet(strSheetName As String)
'On Error GoTo 0
'Application.DisplayAlerts = False
'Sheets(strSheetName).Select
Sheets(strSheetName).Delete
'ActiveWindow.SelectedSheets.Delete
'ActiveSheet.Select
'Range("A10").Select
'Application.DisplayAlerts = True
End Sub