Bonjour,
Je n'ai pas trouvé de réponse sur le site ni sur :google2:
Est-il possible de sauvegarder en .frm un userform créé dynamiquement, pour en faire un formulaire permanent ?
:merci:
Version imprimable
Bonjour,
Je n'ai pas trouvé de réponse sur le site ni sur :google2:
Est-il possible de sauvegarder en .frm un userform créé dynamiquement, pour en faire un formulaire permanent ?
:merci:
bonjour
j'espère que cet exemple, à placer dans un module standard, pourra t'aider.
c'est la partie
qui permet d'exporter l'userform créé dynamiquement.Code:Usf.Export "C:\copieUSF.frm"
Code:
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
55
56
57
58
59
60 Option Explicit Dim Usf As Object Sub lancementProcedure() Dim X As Object Dim i As Integer Dim strList As String strList = "ListBox1" Set X = creationUserForm_Et_listBox_Dynamique(strList) For i = 1 To 10 X.Controls(strList).AddItem "Donnee " & i Next i 'Affichage X.Show '-------- 'Export du UserForm Usf.Export "C:\copieUSF.frm" '-------- 'Suppression du UserForm dans le projet ThisWorkbook.VBProject.VBComponents.Remove Usf Set Usf = Nothing End Sub Function creationUserForm_Et_listBox_Dynamique(nomListe As String) As Object Dim ObjListBox As Object Dim j As Integer Set Usf = ThisWorkbook.VBProject.VBComponents.Add(3) With Usf .Properties("Caption") = "Mon UserForm" .Properties("Width") = 300 .Properties("Height") = 200 End With Set ObjListBox = Usf.Designer.Controls.Add("Forms.ListBox.1") With ObjListBox .Left = 20: .Top = 10: .Width = 90: .Height = 140 .Name = nomListe .Object.ColumnCount = 1 .Object.ColumnWidths = 70 End With With Usf.CodeModule j = .CountOfLines .InsertLines j + 1, "Sub " & nomListe & "_Click()" .InsertLines j + 2, "If Not " & nomListe & ".ListIndex = -1 Then MsgBox " & nomListe .InsertLines j + 3, "End Sub" End With VBA.UserForms.Add (Usf.Name) Set creationUserForm_Et_listBox_Dynamique = UserForms(UserForms.Count - 1) End Function
bonne journée
michel