Sub replaceSheet()
Dim wb1 As ThisWorkbook
Dim wb2 As Workbook
Dim ws As Worksheet
Dim sheetName1 As String, sheetName2 As String
Dim sheetExist1 As Boolean, sheetExist2 As Boolean, tempSheet As Boolean
sheetName1 = "Feuil1"
sheetName2 = "Feuil2"
sheetExist1 = False
sheetExist2 = False
Set wb1 = ThisWorkbook
For Each ws In wb1.Worksheets
If ws.Name = sheetName1 Then
sheetExist1 = True
End If
If ws.Name = sheetName2 Then
sheetExist2 = True
End If
Next ws
For Each wb2 In Workbooks
If wb2.Name <> wb1.Name Then
tempSheet = False
For Each ws In wb2.Worksheets
If sheetExist1 And ws.Name = sheetName1 Then
If wb2.Worksheets.Count = 1 And Not tempSheet Then
ws.Name = "TEMP_SHEET_TO_REMOVE"
tempSheet = True
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
If sheetExist2 And ws.Name = sheetName2 Then
If wb2.Worksheets.Count = 1 And Not tempSheet Then
ws.Name = "TEMP_SHEET_TO_REMOVE"
tempSheet = True
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next ws
If sheetExist1 Then
wb1.Sheets(sheetName1).Copy After:=wb2.Sheets(wb2.Sheets.Count)
End If
If sheetExist2 Then
wb1.Sheets(sheetName2).Copy After:=wb2.Sheets(wb2.Sheets.Count)
End If
If tempSheet Then
Application.DisplayAlerts = False
wb2.Sheets("TEMP_SHEET_TO_REMOVE").Delete
Application.DisplayAlerts = True
End If
End If
Next wb2
End Sub