Test or check if sheet exists

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

    Why not just use a small loop to determine whether the named worksheet exists? Say if you were looking for a Worksheet named "Sheet1" in the currently opened workbook.

    Dim wb as Workbook
    Dim ws as Worksheet
    
    Set wb = ActiveWorkbook
    
    For Each ws in wb.Worksheets
    
        if ws.Name = "Sheet1" then
            'Do something here
        End if
    
    Next
    

提交回复
热议问题