I have two files (A & B), each containing multiple sheets. I want to delete certain sheets.
The problem occurs when sheets I want to delete are already gone.
I introduced error handling. Is there any method to Resume code when encountering errors but also give a dynamic report that shows which file does not contain which sheets?
I would like to contine executing code when there is an error but report which file and which sheet has the error.
Sub Remove_sheets()
Dim A As workbook: Set A = Workbooks("A.xlsx")
Dim B As workbook: Set B = Workbooks("B.xlsx")
Const NameA As String = "A"
Const NameB As String = "B"
On Error GoTo Handling
Application.DisplayAlerts = False
A.Worksheets("Sheet1").Delete 'can be any sheets
B.Worksheets("Sheet5").Delete
B.Worksheets("Sheet5 (2)").Delete
Exit Sub
Handling:
MsgBox "There is no sheet1 in " & NameA & " to be deleted"
Application.DisplayAlerts = True
End Sub