Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Déclaration 2020").Visible = xlSheetVeryHidden
End Sub
Private Sub Workbook_Open()
Dim Mois As String, Ligne1 As Integer, Ligne2 As Long, MoisFin As String
With Sheets("Déclaration 2020")
.Visible = True
.Select
Mois = UCase(Format(DateSerial(Year(Date), Month(Date) + 1, 1), "mmmm"))
.Unprotect "MDP"
Ligne1 = Application.Match(Mois, .[B:B], 0)
On Error Resume Next
Ligne2 = .Range(.Cells(Ligne1, 2), .Cells(1000, 2)).Find("*", , , , xlByRows, xlNext).Row - 2
If Err.Number > 0 Then
Ligne2 = .Range(.Cells(Ligne1, 5), .Cells(1000, 5)).Find("*", , , , xlByRows, xlPrevious).Row
End If
On Error GoTo 0
.Range(.Cells(Ligne1, 2), .Cells(Ligne2, "AE")).Locked = True
.Protect "MDP"
End With
End Sub