Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32.dll" _
(ByVal hWnd As Long, ByVal Idt As Long, ByVal DuréeMS As Long, ByVal AdrSub As LongPtr) As Long
Private Declare PtrSafe Function KillTimer Lib "user32.dll" _
(ByVal hWnd As Long, ByVal Idt As Long) As Long
#Else
Private Declare Function SetTimer Lib "user32.dll" _
(ByVal hWnd As Long, ByVal Idt As Long, ByVal DuréeMS As Long, ByVal AdrSub As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" _
(ByVal hWnd As Long, ByVal Idt As Long) As Long
#End If
Private Temps As Date, Shp As Shape, VitAng As Long, ÇaTourne As Boolean
Public Sub AnimLoading()
Set Shp = Feuil1.Shapes("Image 2")
If Temps = 0 Then
SetTimer Application.hWnd, Idt:=1, DuréeMS:=40, AdrSub:=AddressOf TimerProc
Else
Application.OnTime Temps, "ArrêtRotation", Schedule:=False
End If
Temps = Now + TimeSerial(0, 0, 5)
ÇaTourne = True
Application.OnTime Temps, "ArrêtRotation"
End Sub
Private Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal Idt As Long, ByVal Tic As Long)
On Error Resume Next
If ÇaTourne Then
VitAng = VitAng + 1: If VitAng > 10 Then VitAng = 10
Else
VitAng = VitAng - 1: If VitAng = 0 Then KillTimer Application.hWnd, Idt:=1
End If
Shp.Rotation = (Shp.Rotation + VitAng) Mod 360
If Err Then KillTimer Application.hWnd, Idt:=1
End Sub
Public Sub ArrêtRotation()
ÇaTourne = False
Temps = 0
End Sub