Test or check if sheet exists

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

    Public Function WorkSheetExists(ByVal strName As String) As Boolean
       On Error Resume Next
       WorkSheetExists = Not Worksheets(strName) Is Nothing
    End Function
    
    sub test_sheet()
    
     If Not WorkSheetExists("SheetName") Then
     MsgBox "Not available"
    Else MsgBox "Available"
    End If
    
    End Sub
    

提交回复
热议问题