```
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
```
Tester ou vérifier si une feuille existe
Re: Tester ou vérifier si une feuille existe
Créez une fonction de vérification :
```vba
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 :
```vba
If SheetExists(wkbkdestination, ThisWorkSheet.Name) Then
Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name)
End If
```
```vba
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 :
```vba
If SheetExists(wkbkdestination, ThisWorkSheet.Name) Then
Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name)
End If
```