我一直在做一些研究,并从两个资源中拼凑了一些代码,想知道我整理的代码是否还有改进的空间。我有一个有点笨重的旧代码。
代码:
Dim ws As Worksheet
Dim mySheet1 As Variant
Dim mySheet2 As Variant
Dim mySheet3 As Variant
Dim mySheet4 As Variant
Dim mySheet5 As Variant
mySheet1="S363"
mySheet2="non"
mySheet3="promos"
mySheet4="All Filtered"
mySheet5="Final Send"
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
If mySheet1 = ws.Name Then
ws.Delete
ElseIf mySheet2 = ws.Name Then
ws.Delete
ElseIf mySheet3= ws.Name Then
ws.Delete
ElseIf mySheet4 = ws.Name Then
ws.Delete
ElseIf mySheet5 = ws.Name Then
ws.Delete
End If
Next ws
‘All other instructions here
Application.DisplayAlerts = True
End Sub
你可以尝试这个代码:
如果您确定所有指定的工作表都存在,则可以一次性删除它们: