Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Wkb As Workbook, EndJob As Date, VBC As Object
Set Wkb = ThisWorkbook
EndJob = DateSerial(2017, 9, 1) 'Choisir la date de fin applicatif
If Date >= EndJob Then
'******************
UnprotectVBProject Wkb, "0000" 'Ici
'******************
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With
Application.Quit 'penser à fermer tous les fichiers ouverts avant
SendKeys "%O"
Else
Exit Sub
End If
Application.DisplayAlerts = False
Wkb.Save
End Sub
Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object
Application.ScreenUpdating = False
Set vbProj = WB.VBProject
If vbProj.Protection <> 1 Then Exit Sub 'Voir si utile
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
Application.ScreenUpdating = True
End Sub