Test or check if sheet exists

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

    I know it is an old post, but here is another simple solution that is fast.

    Public Function worksheetExists(ByVal wb As Workbook, ByVal sheetNameStr As String) As Boolean
    
    On Error Resume Next
    worksheetExists = (wb.Worksheets(sheetNameStr).Name <> "")
    Err.Clear: On Error GoTo 0
    
    End Function
    

提交回复
热议问题