Test or check if sheet exists

后端 未结 22 2836
深忆病人
深忆病人 2020-11-21 23:51
Dim wkbkdestination As Workbook
Dim destsheet As Worksheet

For Each ThisWorkSheet In wkbkorigin.Worksheets 
    \'this throws subscript out of range if there is not         


        
22条回答
  •  孤城傲影
    2020-11-22 00:08

    I did another thing: delete a sheet only if it's exists - not to get an error if it doesn't:

    Excel.DisplayAlerts = False 
    Dim WS
    For Each WS In Excel.Worksheets
        If WS.name = "Sheet2" Then
            Excel.sheets("Sheet2").Delete
            Exit For
        End If
    Next
    Excel.DisplayAlerts = True
    

提交回复
热议问题