Bonjour,

je suis perdu, lorsque je cré un userform avec :
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
29
30
31
32
33
34
35
36
37
38
39
 
Sub CreateUsf()
Dim i, x As Integer
Dim nbinstal As Integer
Dim UsfName As String
Dim UsfForm As Object
Dim Obj1 As MSForms.Label
 
nbinstal = ThisWorkbook.Sheets("Données").Cells(28, 2).Value
For i = 1 To nbinstal
    UsfName = ThisWorkbook.Sheets("Données").Cells(30 + i, 1).Value
    If Not usfExists(UsfName) = False Then VBA.UserForms.Add(UsfName).Show: Exit Sub
 
    Set UsfForm = Application.ThisWorkbook.VBProject.VBComponents.Add(3)
    With UsfForm
        .Properties("Name") = UsfName
        .Properties("Caption") = UsfName
        .Properties("Width") = 550
        .Properties("Height") = 600
        .Properties("ScrollHeight") = 930
        .Properties("ScrollBars") = 2
        .Properties("BackColor") = &HFF8080
    End With
 
    Set Obj1 = UsfForm.Designer.Controls.Add("forms.label.1", , True)
        With Obj1
            .Left = 18
            .Top = 12
            .Width = 216
            .Height = 18
            .Caption = "Données générales sur l'installation :"
            .FontSize = 11
            .FontBold = True
            .BackColor = &HFF8080
        End With
    VBA.UserForms.Add(UsfName).Show
 
Next i
End Sub
le ou les userforms sont bien créés et s'affiche à l'écran, mais dés que je veux mettre du code dans les userforms avec:
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
Sub CreateUsf()
Dim i, x As Integer
Dim nbinstal As Integer
Dim UsfName As String
Dim UsfForm As Object
Dim Obj1 As MSForms.Label
 
nbinstal = ThisWorkbook.Sheets("Données").Cells(28, 2).Value
For i = 1 To nbinstal
    UsfName = ThisWorkbook.Sheets("Données").Cells(30 + i, 1).Value
    If Not usfExists(UsfName) = False Then VBA.UserForms.Add(UsfName).Show: Exit Sub
 
    Set UsfForm = Application.ThisWorkbook.VBProject.VBComponents.Add(3)
    With UsfForm
        .Properties("Name") = UsfName
        .Properties("Caption") = UsfName
        .Properties("Width") = 550
        .Properties("Height") = 600
        .Properties("ScrollHeight") = 930
        .Properties("ScrollBars") = 2
        .Properties("BackColor") = &HFF8080
    End With
 
    Set Obj1 = UsfForm.Designer.Controls.Add("forms.label.1", , True)
        With Obj1
            .Left = 18
            .Top = 12
            .Width = 216
            .Height = 18
            .Caption = "Données générales sur l'installation :"
            .FontSize = 11
            .FontBold = True
            .BackColor = &HFF8080
        End With
 
    With UsfForm.CodeModule
        x = .CountOfLines
        If x = 2 Then
        .InsertLines x, "": x = x + 1
        Else
            x = 1
        End If
        .InsertLines x, "Private Sub CheckAutreMAuto_Click()": x = x + 1
        .InsertLines x, "If CheckAutreMAuto.Value = False Then": x = x + 1
        .InsertLines x, "CombienMAuto.Enabled = False": x = x + 1
        .InsertLines x, "Else: CombienMAuto.Enabled = True": x = x + 1
        .InsertLines x, "End If": x = x + 1
        .InsertLines x, "End Sub": x = x + 1
    End with
    VBA.UserForms.Add(UsfName).Show
 
Next i
End Sub
et ben les userforms ne veulent plus s'afficher alors que le premier se crée bien avec le code dedans.
la solution est peut être toute simple mais je ne comprends vraiment pas ce qui cloche.