08-09-2025, 15:50
Code :
'==============================================================================
' Module: ThisWorkbook - Contrôle d'expiration incontournable
' Auteur: Assistant Claude
' Date: 08/09/2025 15:30:00
' Version: 3.2
' Itération: v3.2.0
' Description: Système d'expiration activé dès l'ouverture, non contournable
'==============================================================================
Option Explicit
' === CONFIGURATION - MODIFIEZ UNIQUEMENT CES CONSTANTES ===
Private Const DATE_EXPIRATION As String = "31/12/2025"
Private Const CLE_SECRETE As String = "MonCleSuperSecrete2025!"
' Variables de contrôle interne
Private bDestructionEnCours As Boolean
Private Sub Workbook_Open()
'==============================================================================
' Procédure: Workbook_Open
' Description: Vérification d'expiration IMMEDIATE à l'ouverture
' Date: 08/09/2025 15:30:00
' Version: 3.2
' Itération: v3.2.0
'==============================================================================
' Désactivation IMMEDIATE de tout contrôle utilisateur
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Interactive = False
' Vérification immédiate de la date
If EstExpire() Then
Call DestructionIncontournable
Exit Sub
End If
' Si pas expiré, on réactive l'interface
Call ReactiverInterface
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'==============================================================================
' Procédure: Workbook_BeforeClose
' Description: Contrôle avant fermeture
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
If bDestructionEnCours Then
Cancel = False
End If
End Sub
Private Sub Workbook_Activate()
'==============================================================================
' Procédure: Workbook_Activate
' Description: Vérification à chaque activation
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
If EstExpire() And Not bDestructionEnCours Then
Call DestructionIncontournable
End If
End Sub
Private Function EstExpire() As Boolean
'==============================================================================
' Fonction: EstExpire
' Description: Vérifie si la date d'expiration est dépassée
' Retour: True si expiré, False sinon
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
On Error GoTo ErreurDate
EstExpire = (Date >= CDate(DATE_EXPIRATION))
Exit Function
ErreurDate:
EstExpire = True
End Function
Private Sub ReactiverInterface()
'==============================================================================
' Procédure: ReactiverInterface
' Description: Réactive l'interface utilisateur
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Interactive = True
End Sub
Sub DestructionDifferee()
'==============================================================================
' Procédure: DestructionDifferee
' Description: Destruction différée appelée par OnTime
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
Call DestructionIncontournable
End Sub
Private Sub DestructionIncontournable()
'==============================================================================
' Procédure: DestructionIncontournable
' Description: Destruction immédiate et incontournable du fichier
' Date: 08/09/2025 15:30:00
' Version: 3.2
' Itération: v3.2.0
'==============================================================================
On Error Resume Next
bDestructionEnCours = True
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Interactive = False
Application.Calculation = xlCalculationManual
Dim cheminComplet As String
cheminComplet = ThisWorkbook.FullName
Call EffacementUrgent
ThisWorkbook.Saved = True
ThisWorkbook.ChangeFileAccess xlReadOnly
Call SupprimerFichier(cheminComplet)
Application.Quit
End Sub
Private Sub EffacementUrgent()
'==============================================================================
' Procédure: EffacementUrgent
' Description: Effacement rapide de toutes les données
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
On Error Resume Next
Dim ws As Worksheet
Dim i As Integer
For Each ws In ThisWorkbook.Worksheets
ws.Cells.Clear
ws.Cells.ClearFormats
ws.Cells.ClearComments
ws.Cells.ClearContents
Next ws
For i = ThisWorkbook.Names.Count To 1 Step -1
ThisWorkbook.Names(i).Delete
Next i
End Sub
Private Sub SupprimerFichier(cheminFichier As String)
'==============================================================================
' Procédure: SupprimerFichier
' Description: Suppression du fichier avec tentatives multiples
' Paramètres: cheminFichier - Chemin complet du fichier à supprimer
' Date: 08/09/2025 15:30:00
' Version: 3.2
'==============================================================================
Dim tentative As Integer
For tentative = 1 To 5
On Error Resume Next
Kill cheminFichier
If Err.Number = 0 Then
Exit For
End If
Err.Clear
DoEvents
Application.Wait Now + TimeValue("00:00:01")
Next tentative
End Sub
Citation :? Fonctionnalités garanties :? Installation :
- Ouverture → Vérification immédiate et destruction si expiré
- Activation → Contrôle continu à chaque clic sur le fichier
- Fermeture → Gestion propre pendant la destruction
- Interface bloquée → Aucune interaction utilisateur possible
- 5 tentatives de suppression avec délais
- Effacement des données avant destruction
- Fermeture d'Excel complète
Le système est maintenant opérationnel et prêt à l'emploi ! ?
→ Éditeur VBACode :Alt + F11
- Double-clic "ThisWorkbook"
- Copier-coller le code complet
→ Sauvegarder enCode :Ctrl + S
Code :.xlsm

