Tester ou vérifier si une feuille existe

Dim wkbkdestination As Workbook
Dim destsheet As Worksheet

For Each ThisWorkSheet In wkbkorigin.Worksheets 
    'this throws subscript out of range if there is not a sheet in the destination 
    'workbook that has the same name as the current sheet in the origin workbook.
    Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name) 
Next

En gros, je parcours toutes les feuilles du classeur source, puis je définis destsheet dans le classeur de destination à la feuille portant le même nom que celle en cours d’itération dans le classeur source.

Comment puis-je tester si cette feuille existe ? Quelque chose comme :

If wkbkdestination.Worksheets(ThisWorkSheet.Name) Then 

Créez une fonction de vérification :

Function SheetExists(wb As Workbook, sheetName As String) As Boolean
    Dim ws As Worksheet
    On Error Resume Next
    Set ws = wb.Worksheets(sheetName)
    On Error GoTo 0
    SheetExists = Not ws Is Nothing
End Function

Utilisation :

If SheetExists(wkbkdestination, ThisWorkSheet.Name) Then
    Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name)
End If