Private Sub Workbook_Open()
Application.ScreenUpdating = False
Worksheets("Relevé_Hebdo").Unprotect
Sheets("Récap_Mensuelle").Select
If Cells(4, 1) = Empty Then
Dim mois As String
Dim Année As String
Dim Titre As String
Dim Récap_Mensuelle As String
Dim Relevé_Hebdo As String
Dim Semaine As String
Dim Sme As String
Dim c As Range
Dim DateDepart As Date
Dim Sunday As Integer
Dim D As Date
Dim j As Date
Dim k As Date
'Date départ au 1er du mois
DateDepart = DateSerial(Year(Date), Month(Date), 1)
k = DateDepart
D = Date
j = D + 1 - DatePart("w", D, vbMonday, vbFirstFourDays)
mois = Format(j + 3, "mmmm") 'mois contenant au moins 4 jours de la semaine.
Année = Format(DateDepart, "yyyy")
Titre = "MOIS DE" & " " & mois & " " & Année
Cells(4, 1) = UCase(Titre)
Sheets("Relevé_Hebdo").Select
Worksheets("Relevé_Hebdo").Unprotect
mois = Format(j + 3, "mmmm")
Année = Format(Now, "yyyy")
Titre = "MOIS DE" & " " & mois & " " & Année
Cells(1, 1) = UCase(Titre)
If D > k Then
D = k + 1
Else
D = D
End If
For Each c In Range("C1,E1,G1,I1,K1")
j = D + 1 - DatePart("w", D, vbMonday, vbFirstFourDays)
c = "Sem " & DatePart("ww", j, vbMonday, vbFirstFourDays)
D = D + 7 'DateDepart = DateDepart + 7 'Incrémente la date de 7 jours (1 semaine)
Next
Worksheets("Relevé_Hebdo").Protect
End If
Application.ScreenUpdating = True
End Sub