循环工作表并删除

时间:2019-05-17 08:16:34

标签: excel vba

我试图循环工作表并删除不需要的。问题是我想基于VBA编辑器(名称)进行循环和删除,但出现错误。循环工作完美。任何帮助将不胜感激。

代码:

Sub Remove_Sheets()

    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets

        If ws.Name = wsOriginal Or ws.Name = wsRecords Then
        Else
            ws.Delete
        End If

    Next ws

End Sub

图片:

enter image description here

1 个答案:

答案 0 :(得分:5)

问题解决了。我已替换:

If ws.Name = wsOriginal Or ws.Name = wsRecords Then

具有:

If ws.CodeName = "wsOriginal" Or ws.CodeName = "wsRecords" Then