Option Explicit
Private Planifications As New Collection
Public Function IdtPlanif(ByVal Source As Planification) As String
IdtPlanif = Rnd * &H1000000
Application.OnTime Source.HeureOT, "'OnTimeJoue """ & IdtPlanif & """'"
Planifications.Add Source, IdtPlanif
End Function
Public Sub StopperPlanif(ByVal IdtPlanif As String)
Dim Planif As Planification
On Error Resume Next: Set Planif = Planifications(IdtPlanif): If Err Then Exit Sub
On Error GoTo 0
Application.OnTime Planif.HeureOT, "'OnTimeJoue """ & IdtPlanif & """'", Schedule:=False
Planifications.Remove IdtPlanif
End Sub
Public Sub OnTimeJoue(ByVal IdtPlanif As String)
Dim Planif As Planification
On Error Resume Next: Set Planif = Planifications(IdtPlanif): If Err Then Exit Sub
On Error GoTo 0
Planifications.Remove IdtPlanif
Planif.OnTimeJoueÉchoit
End Sub
Public Sub DéplanifierTout()
Do While Planifications.Count > 0: Planifications(1).Déplanifier: Loop
End Sub