Test or check if sheet exists

后端 未结 22 2857
深忆病人
深忆病人 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:24

    If you are a fan of WorksheetFunction. or you work from a non-English country with a non-English Excel this is a good solution, that works:

    WorksheetFunction.IsErr(Evaluate("'" & wsName & "'!A1"))
    

    Or in a function like this:

    Function WorksheetExists(sName As String) As Boolean
        WorksheetExists = Not WorksheetFunction.IsErr(Evaluate("'" & sName & "'!A1"))
    End Function
    

提交回复
热议问题