VBA删除第一个sheet后的所有sheet

Sub clearSheets()
    Dim worksheets As Sheets
    Dim ws As Worksheet
    Dim idx As Integer
    Set worksheets = ActiveWorkbook.worksheets
    idx = worksheets.Count
    Application.DisplayAlerts = False
    While idx > 1
        Set ws = worksheets.Item(idx)
        ws.Delete
        idx = worksheets.Count
    Wend
    Application.DisplayAlerts = True
End Sub

你可能感兴趣的:(编程语言,vba,excel)