1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Option Explicit
Public yaLastDate As Date 'Variable permettant d'effacer la tache planifiée..
Public yaLastContinue As Date 'Variable permettant d'effacer la tache planifiée..
Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef plii As LASTINPUTINFO) As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
'
' Procedure yaTestActivité .., à appeller au sur
'avec ThisWorkBook_open, ensuite elle s'appelle" toutes les secondes pour controler l'activité
Sub yaTestActivite()
Dim yaLastInput As LASTINPUTINFO
Static yaMemoLastInput As Long
yaLastInput.cbSize = Len(yaLastInput)
If GetLastInputInfo(yaLastInput) <> 0 Then
If yaMemoLastInput <> yaLastInput.dwTime Then
yaMemoLastInput = yaLastInput.dwTime 'Memorise "le moment" de la derniére activité.
yaContinue 'Le moment de la derniére activité à évoluer on continue.
End If
End If
Application.OnTime Now + TimeSerial(0, 0, 1), "yaTestActivite" 'Test activité toutes les 10s
End Sub
Sub yaStoppe()
Dim classeur As Excel.Workbook
Application.DisplayAlerts = False
For Each classeur In Workbooks
If classeur.Name <> "Base des Incidents.xls" Then
Exit For
End If
GoTo fin
Next classeur
Windows("Base des Incidents.xls").Activate
ActiveWorkbook.Close
fin:
Application.Quit
End Sub
'
' yaContinue doit être appellé au moins toutes les 30s sinon
' elle appelle la procédure yaStoppe..
'
'
Sub yaContinue()
Static yaLastDate As Date 'Variable statique permettant d'effacer la tache planifiée..
If yaLastDate <> 0 Then
' Efface la date planifiée ..
On Error Resume Next
Application.OnTime EarliestTime:=yaLastDate, _
Procedure:="yaStoppe", Schedule:=False
End If
'Calcul prochaine date dans 5 minutes
yaLastDate = Now + TimeSerial(0, 0, 3000)
Application.OnTime yaLastDate, "yaStoppe" 'Appel procédure fin application
End Sub |