Bonjour,
J'essaie actuellement de réaliser un chronomètre sous vba excel 2007. Etant débutant sous vba et après quelques recherches j'en ai trouvé un qui me convient pour l'instant mais j'ai un problème: Peut-on avoir un userform actif (Ici mon chrono) et en même temps travailler sur sa feuille excel?
Je m'explique: Ce chrono doit servir à compter des tours mais on peut très bien décider de rajouter des commentaires tour par tour, ou pas. C'est pourquoi j'aimerais avoir toujours la main sur ma feuille avec le chrono fonctionnant. La seule "solution" que j'avais trouvée me rendait la main mais me stoppait mon chrono. Voici la définition de mon userform: (4boutons 3 labels). Merci d'avance!
Option Explicit
Dim marche As Boolean, arret As Boolean
Private Sub QUITTER_Click()
End
End Sub
Sub chrono()
Dim départ As Double, ARRIVÉE As Double, durée As Double
Dim j As Long, i As Long, sd As Long, ms As Long
Dim mn As Long, tps As String, Temps As Double
i = 14
départ = GetTickCount&
'DoEvents
Do
Do While marche And Not arret '-> le bouton PAUSE entraîne [marche = False] => Sortie de cette boucle
ARRIVÉE = GetTickCount&
durée = ARRIVÉE - départ
Label1.Caption = durée
[A1] = durée
DoEvents 'Laisse un délai pour l'affichage (tout petit petit...)
Loop
If Not arret And Not marche Then
durée = ARRIVÉE - départ
mn = Int(durée / 1000 / 60)
sd = Int((durée / 1000) - (mn * 60))
ms = durée - (sd * 1000) - (mn * 1000 * 60)
tps = mn & ":" & sd & ":" & ms
Labeltemp.Caption = tps
Temps = Val(mn & "." & Right("00" & sd, 2) & Right("000" & ms, 3))
DoEvents
marche = True
End If
Loop Until arret
durée = ARRIVÉE - départ
mn = Int(durée / 1000 / 60)
sd = Int((durée / 1000) - (mn * 60))
ms = durée - (sd * 1000) - (mn * 1000 * 60)
tps = mn & ":" & sd & ":" & Right("000" & ms, 3)
LabelFin.Caption = tps
Temps = Val(mn & "." & Right("00" & sd, 2) & Right("000" & ms, 3))
End Sub
Private Sub DEPART_Click()
If Not marche Then
Init
arret = False
marche = True
chrono
End If
End Sub
Private Sub PAUSE_Click()
Dim j As Long
marche = Not marche
For j = 1 To 10000
DoEvents
Next
End Sub
Sub Init()
Labeltemp.Caption = "00:00:00"
LabelFin.Caption = "00:00:00"
End Sub
Private Sub ARRIVEE_Click()
arret = True
marche = False
End Sub
Private Sub UserForm_Initialize()
Init
End Sub
J'essaie actuellement de réaliser un chronomètre sous vba excel 2007. Etant débutant sous vba et après quelques recherches j'en ai trouvé un qui me convient pour l'instant mais j'ai un problème: Peut-on avoir un userform actif (Ici mon chrono) et en même temps travailler sur sa feuille excel?
Je m'explique: Ce chrono doit servir à compter des tours mais on peut très bien décider de rajouter des commentaires tour par tour, ou pas. C'est pourquoi j'aimerais avoir toujours la main sur ma feuille avec le chrono fonctionnant. La seule "solution" que j'avais trouvée me rendait la main mais me stoppait mon chrono. Voici la définition de mon userform: (4boutons 3 labels). Merci d'avance!
Option Explicit
Dim marche As Boolean, arret As Boolean
Private Sub QUITTER_Click()
End
End Sub
Sub chrono()
Dim départ As Double, ARRIVÉE As Double, durée As Double
Dim j As Long, i As Long, sd As Long, ms As Long
Dim mn As Long, tps As String, Temps As Double
i = 14
départ = GetTickCount&
'DoEvents
Do
Do While marche And Not arret '-> le bouton PAUSE entraîne [marche = False] => Sortie de cette boucle
ARRIVÉE = GetTickCount&
durée = ARRIVÉE - départ
Label1.Caption = durée
[A1] = durée
DoEvents 'Laisse un délai pour l'affichage (tout petit petit...)
Loop
If Not arret And Not marche Then
durée = ARRIVÉE - départ
mn = Int(durée / 1000 / 60)
sd = Int((durée / 1000) - (mn * 60))
ms = durée - (sd * 1000) - (mn * 1000 * 60)
tps = mn & ":" & sd & ":" & ms
Labeltemp.Caption = tps
Temps = Val(mn & "." & Right("00" & sd, 2) & Right("000" & ms, 3))
DoEvents
marche = True
End If
Loop Until arret
durée = ARRIVÉE - départ
mn = Int(durée / 1000 / 60)
sd = Int((durée / 1000) - (mn * 60))
ms = durée - (sd * 1000) - (mn * 1000 * 60)
tps = mn & ":" & sd & ":" & Right("000" & ms, 3)
LabelFin.Caption = tps
Temps = Val(mn & "." & Right("00" & sd, 2) & Right("000" & ms, 3))
End Sub
Private Sub DEPART_Click()
If Not marche Then
Init
arret = False
marche = True
chrono
End If
End Sub
Private Sub PAUSE_Click()
Dim j As Long
marche = Not marche
For j = 1 To 10000
DoEvents
Next
End Sub
Sub Init()
Labeltemp.Caption = "00:00:00"
LabelFin.Caption = "00:00:00"
End Sub
Private Sub ARRIVEE_Click()
arret = True
marche = False
End Sub
Private Sub UserForm_Initialize()
Init
End Sub