Formulaire personalisé

Bonsoir,

J’essaie de faire un formulaire personnaliser en VBA mais quand je vais en debug, j'ai une erreur "Erreur d’exécution -2147024809 (800070057) : Objet spécifié introuvable." et ceux la se met en surbrillance sur "Private Sub UserForm_Initialize()". Je vous met en pièces joint : le document excel avec le code VBA.

Option Explicit
Dim Ws As Worksheet

'Pour le formulaire
Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer

    ComboBox2.ColumnCount = 1 'Pour la liste déroulante Categorie
    ComboBox2.List() = Array("1", "2", "3")
    ComboBox3.ColumnCount = 2 'Pour la liste déroulante Achat/Vente
    ComboBox3.List() = Array("Achats", "Ventes")
    Set Ws = Sheets("test") 'Correspond au nom de votre onglet dans le fichier Excel
    With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
            .AddItem Ws.Range("A" & J)
        Next J
    End With
    For I = 1 To 7
        Me.Controls("TextBox" & I).Visible = True
    Next I
End Sub
'Pour la liste déroulante Code
Private Sub ComboBox1_Change()
    Dim Ligne As Long
    Dim I As Integer

    If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    Ligne = Me.ComboBox1.ListIndex + 2
    ComboBox2 = Ws.Cells(Ligne, "B")
    For I = 1 To 7
        Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 2)
    Next I
End Sub

'Pour le bouton Nouveau contact
Private Sub CommandButton1_Click()
    Dim L As Integer
    Dim J As Long
    Dim I As Integer

    If MsgBox("Confirmez-vous l'insertion de cette ligne ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
        L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide
        Range("A" & L).Value = ComboBox1
        Range("B" & L).Value = ComboBox2
    Range("C" & L).Value = ComboBox3
        Range("D" & L).Value = TextBox1
        Range("E" & L).Value = TextBox2
        Range("F" & L).Value = TextBox3
        ComboBox1.Clear
        Set Ws = Sheets("test") 'Correspond au nom de votre onglet dans le fichier Excel
        With Me.ComboBox1
            For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
                .AddItem Ws.Range("A" & J)
            Next J
        End With
    End If
End Sub

'Pour le bouton Modifier
Private Sub CommandButton2_Click()
    Dim Ligne As Long
    Dim I As Integer

    If MsgBox("Confirmez-vous la modification de cette ligne ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
        If Me.ComboBox1.ListIndex = -1 Then Exit Sub
        Ligne = Me.ComboBox1.ListIndex + 2
        Ws.Cells(Ligne, "B") = ComboBox2
        For I = 1 To 3
            If Me.Controls("TextBox" & I).Visible = True Then
                Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & I)
            End If
        Next I
    End If
End Sub

'Pour le bouton Quitter
Private Sub CommandButton3_Click()
    Unload Me
End Sub
16test.xlsm (15.81 Ko)

Bonne soirée

Bonsoir,

C'est ce qui arrive lorsqu'on veut manipuler des contrôles qui n'existent pas dans le Userform...

Cherche les TextBox4 à 7...

Rechercher des sujets similaires à "formulaire personalise"