Microsoft 365 Poursuivre ou pas la macro

Francky79

XLDnaute Occasionnel
Bonjour,

Dans le code de mon ScrollBar1_Change j'aimerais pouvoir arrêter la procédure du code si bouton sur OF et continuer la procédure si bouton sur ON.
Mais je ne sais pas comment finaliser le code
Code du bouton
VB:
Private Sub CommandButton6_Click()
With CommandButton6
  If .Caption Like "*ON" Then
  CommandButton6.BackColor = RGB(255, 0, 0)
    arret = True
    .Caption = "OF"
  Else
  CommandButton6.BackColor = RGB(0, 255, 0)
    arret = False
    .Caption = "ON"
  End If
End With
End Sub

Code pour le ScrollBar1
Code:
Private Sub ScrollBar1_Change()
Dim Chemin As String, Ligne As Integer, img As Object
    Ligne = ScrollBar1.Value

    Set img = WebBrowser1.Document.getelementsbytagname("img")(0)
    TextBox1 = ActiveSheet.Range("E" & Ligne)
    TextBox2 = ActiveSheet.Range("Q" & Ligne)
    TextBox2.BackColor = ActiveSheet.Range("Q" & Ligne).DisplayFormat.Interior.Color
    TextBox3 = ActiveSheet.Range("J" & Ligne)
    TextBox3.BackColor = ActiveSheet.Range("V" & Ligne).DisplayFormat.Interior.Color
    TextBox4 = ActiveSheet.Range("N" & Ligne)
    TextBox4.BackColor = ActiveSheet.Range("N" & Ligne).DisplayFormat.Interior.Color
    
        
    Chemin = "C:\Users\franck.delaunay\Documents\Thierry\Data systems\" & Cells(Ligne, 6) & ".jpg"
    img.src = ""
    If Dir(Chemin) <> "" Then
        img.src = Chemin
    End If
    
    With CommandButton6 ' Si bouton sur OF on revient au début
    arret = False       ' Si bouton sur ON on continue
    End With
    
    
    With UserForm10
    .Width = 800
    End With
    Cells.Find(What:=TextBox1.Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Sheets("Usinage").Select
    Cells.FindNext(After:=ActiveCell).Activate
Dim lig&, commentaire As Comment
lig = ActiveCell.Row
    TextBox7.Text = ActiveCell.Value
UserForm10.TextBox7.BackColor = ActiveCell.DisplayFormat.Interior.Color
UserForm10.TextBox8.Text = Range("AO" & lig).Value
UserForm10.TextBox8.BackColor = Range("AO" & lig).DisplayFormat.Interior.Color
UserForm10.TextBox9.Text = Range("AP" & lig).Value
UserForm10.TextBox9.BackColor = Range("AP" & lig).DisplayFormat.Interior.Color

Sheets("Base").Select
With CommandButton6
    arret = True
    End With
End Sub

Merci pour votre aide.
 

Franc58

XLDnaute Occasionnel
Bonjour,
Vous pouvez ajouter une condition au début de votre procédure ScrollBar1_Change pour vérifier l’état de arret. Si arret est True (ce qui signifie que le bouton est sur “OF”), alors vous pouvez utiliser Exit Sub pour arrêter la procédure. Voici comment vous pouvez le faire :

Private Sub ScrollBar1_Change()
If arret Then Exit Sub ' Ajoutez cette ligne

' Le reste de votre code...
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 206
Messages
2 086 223
Membres
103 159
dernier inscrit
FBallea