Bonjour à tous,

J'ai un souci avec des évènements VBA non sollicités (volontairement) qui se déclenchent :

L'évènement _Enter d'une TextBox fait apparaître une InputBox. Si on entre un nombre, un bouton s'active. J'appuie sur ce bouton pour mettre à jour une Spreadsheet. Mais ensuite, l'évènement _Enter de la même TextBox se déclenche à nouveau et semble se déclencher également lors de la fermeture du UserForm ce qui fait qu'une InputBox reste seule à l'écran après la fermeture du programme.

Application.EnableEvents = False ne résout pas le problème. Je soupçonnais l'évènement _Exit d'y être pour quelque chose mais en le commentant entièrement je me suis rendu compte que ce n'était pas ça.

L'évènement se déclenche donc normalement et de manière voulue une première fois puis de manière non sollicitée après mise à jour de ma Spreadsheet en appuyant sur le bouton dédié puis dans la foulée de l'évènement _Click de ce bouton il se reproduit. Si avant de cliquer sur le bouton j'appuie sur Tab ou Entrer ou que je clique directement le résultat est le même.

Mon UserForm :
Nom : Capture.JPG
Affichages : 189
Taille : 106,3 Ko

La TextBox impliquée contient le texte "Pression (0 à 1000 mbar)" et s'appelle "TextBoxPression". La commande bouton sur laquelle je clique est "CommandeValiderWEP" et se trouve en bas à gauche. Ci-dessous les codes évènementiels :

De TextBoxPression :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
Private Sub TextBoxPression_Enter()
    If Me.TextBoxPression.Text <> "" Then
        Pression = Application.InputBox(Prompt:="Pression (mbar) =", Title:="Pression (mbar)", Default:=Me.TextBoxPression.Text, Top:=Me.TextBoxPression.Top, Type:=1)
        If VarType(Pression) = vbDouble Then
            Me.TextBoxPression.Value = Pression
            Me.CommandeValiderWEP.Enabled = True
        Else
            Me.TextBoxPression.Text = "Pression (0 à 1000 mbar)"
        End If
    End If
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Private Sub TextBoxPression_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Me.CommandeValiderWEP.Enabled = False Then
        Pression = Application.InputBox(Prompt:="Pression (mbar) =", Title:="Pression (mbar)", Default:=Me.TextBoxPression.Text, Top:=Me.TextBoxPression.Top, Type:=1)
        If VarType(Pression) = vbDouble Then
            Me.CommandeValiderWEP.Enabled = True
        End If
    Else
        Me.TextBoxPression.Text = "Pression (0 à 1000 mbar)"
    End If
End Sub
De "CommandeValiderWEP" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub CommandeValiderWEP_Click()
If Me.TextBoxPastille.TextLength > 0 Then
    Dim NumeroPastille As Integer
    NumeroPastille = CInt(Right(Me.TextBoxPastille.Value, Me.TextBoxPastille.TextLength - InStr(Me.TextBoxPastille.Value, " ")))
    If NumeroPastille = 1 Then
        With Me.SpreadsheetWEP.Range(Me.SpreadsheetWEP.Cells(Me.SpreadsheetWEP.Range("NumeroPastille").Row + NumeroPastille, _
            Me.SpreadsheetWEP.Range("NumeroPastille").Column), Me.SpreadsheetWEP.Cells(Me.SpreadsheetWEP.Range("EcartRelatifWEP").Row + NumeroPastille, _
                Me.SpreadsheetWEP.Range("EcartRelatifWEP").Column))
                    .Font.Bold = False
                    With .Interior
                        .ColorIndex = xlColorIndexNone 'aucun remplissage
                    End With
        End With
    Else
        Me.SpreadsheetWEP.Rows(Me.SpreadsheetWEP.Range("NumeroPastille").Row + NumeroPastille).Insert Shift:=xlShiftDown
    End If
    Me.SpreadsheetWEP.Cells(Me.SpreadsheetWEP.Range("NumeroPastille").Row, _
        Me.SpreadsheetWEP.Range("NumeroPastille").Column) _
            .Offset(RowOffset:=NumeroPastille, ColumnOffset:=0).Value = NumeroPastille
    Dim WEP As Double
    WEP = Pression
    Me.SpreadsheetWEP.Cells(Me.SpreadsheetWEP.Range("WEP").Row, _
        Me.SpreadsheetWEP.Range("WEP").Column) _
            .Offset(RowOffset:=NumeroPastille, ColumnOffset:=0).Value = WEP
    Me.TextBoxPastille.Value = "Pastille " & NumeroPastille + 1
    Me.CommandeValiderWEP.Enabled = False
End If
End Sub
Auriez-vous une explication qui me permette de corriger ce problème ?