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
| Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
#Else
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#End If
Private oTemp As Range
Public Sub AddClock(ByVal Cell As Range)
If oTemp Is Nothing Then
With Cell
Set oTemp = Cell
.FormulaR1C1 = "=TEXT(NOW(),""hh:mm:ss"")"
Call SetTimer(Application.hwnd, 0, 1000, AddressOf TimerProc)
End With
End If
End Sub
Public Sub RemoveClock(ByVal Cell As Range)
If Not oTemp Is Nothing Then
With Cell
KillTimer Application.hwnd, 0
.FormulaR1C1 = vbNullString
.Interior.ColorIndex = xlNone
Set oTemp = Nothing
End With
End If
End Sub
Private Sub TimerProc(ByVal hwnd As Long, ByVal MSG As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error GoTo errHandler
oTemp.Interior.ColorIndex = IIf(Int(dwTimer / 1000) Mod 2 = 0, xlNone, 6)
oTemp.Calculate
Exit Sub
errHandler:
KillTimer Application.hwnd, 0
End Sub |
Partager