Salut à tous
J'ai eu un code qui me permet d'arrêter une macro en cours de traitement.
Elle fonctionnait bien mais quand j'ai essayé de l'adapter à mon cas réel, j'ai raté.
Il y'a débogage et cette partie du code est soulignée :
Merci de me donner un coup de main à partir du code ci-dessous:
J'ai eu un code qui me permet d'arrêter une macro en cours de traitement.
Elle fonctionnait bien mais quand j'ai essayé de l'adapter à mon cas réel, j'ai raté.
Il y'a débogage et cette partie du code est soulignée :
Code:
If getkeystate(27) > 0 Then
Code:
Option Explicit
Declare Function getkeystate Lib "user32" (ByVal nvirtkey As Long) As Integer
Dim noaction As Boolean
Sub activePack()
'On Error GoTo gestionerreur
Dim I As Integer
If MsgBox("ASSUREZ-VOUS QUE VOTRE", vbYesNo, "Demande de confirmation") = vbYes Then
noaction = False
AppActivate "NOM DU LOGICIEL ICI"
'POSITIONNEZ-VOUS SUR LE MENU
For I = 3 To 6
SendKeys Cells(I, 10).Value, True
attendre 1
If noaction Then Exit Sub
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
SendKeys "N" & Chr(13), True
attendre 1
If noaction Then Exit Sub
SendKeys "{LEFT}"
SendKeys "{ENTER}"
attendre 0.6
If noaction Then Exit Sub
For I = 7 To 43
SendKeys Cells(I, 10).Value, True
attendre 1
If noaction Then Exit Sub
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
SendKeys "+{F3}"
attendre 0.6
If noaction Then Exit Sub
For I = 44 To 51
SendKeys Cells(I, 10).Value, True
attendre 1
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
SendKeys "+{F6}"
attendre 0.6
If noaction Then Exit Sub
'For I = 51 To 51
'SendKeys Cells(I, 10).Value, True
'attendre 0.6
'SendKeys "~"
'attendre 1
End If
Exit Sub
gestionerreur:
MsgBox "fichier non ouvert ou réduit dans la barre des tâches : abandon"
End Sub
Sub activesimple()
Dim I As Integer
'On Error GoTo gestionerreur
If MsgBox("ASSUREZ-VOUS QUE VOTRE", vbYesNo, "Demande de confirmation") = vbYes Then
noaction = False
AppActivate "NOM DU LOGICIEL ICI"
'POSITIONNEZ-VOUS SUR LE MENU
For I = 3 To 43
SendKeys Cells(I, 10).Value, True
attendre 1
If noaction Then Exit Sub
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
SendKeys "+{F3}"
attendre 0.6
If noaction Then Exit Sub
For I = 44 To 51
SendKeys Cells(I, 10).Value, True
attendre 1
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
SendKeys "+{F6}"
attendre 0.6
If noaction Then Exit Sub
For I = 52 To 52
SendKeys Cells(I, 10).Value, True
attendre 1
If noaction Then Exit Sub
SendKeys "~"
attendre 0.6
If noaction Then Exit Sub
Next
End If
Exit Sub
gestionerreur:
MsgBox "fichier non ouvert ou réduit dans la barre des tâches : abandon"
End Sub
Sub attendre(sec%)
Dim deb&, fin&
deb = Timer
fin = deb + sec%
Do Until Timer >= fin
DoEvents
If getkeystate(27) > 0 Then
If MsgBox("Confirmation arrêt macro", vbOKCancel + vbQuestion) = vbOK Then
SendKeys Chr(27)
noaction = True
Exit Sub
End If
SendKeys Chr(27)
End If
Loop
End Sub