Création d'un userform avec listebox

Résolu
kharon_rp Messages postés 3 Date d'inscription mercredi 12 avril 2006 Statut Membre Dernière intervention 24 avril 2006 - 14 avril 2006 à 11:27
kharon_rp Messages postés 3 Date d'inscription mercredi 12 avril 2006 Statut Membre Dernière intervention 24 avril 2006 - 19 avril 2006 à 09:44
Bonjour,

Je voudrais créer un UserForm avec ListBox mais uniquement avec du code VBA.

Qui peut me dire comment faire ?

Merci de votre aide

3 réponses

kharon_rp Messages postés 3 Date d'inscription mercredi 12 avril 2006 Statut Membre Dernière intervention 24 avril 2006
19 avril 2006 à 09:44
Bonjour Michel,

Merci pour ton aide, il ne me reste plus qu'à poser deux boutons et ce sera exploitable.

Bonne journée
3
michelxld Messages postés 402 Date d'inscription vendredi 6 août 2004 Statut Membre Dernière intervention 12 octobre 2008 32
16 avril 2006 à 20:56
bonsoir

j'espere que cet exemple pourra t'aider

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


X.Show


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 ListBox1.ListIndex = -1 Then MsgBox ListBox1"
.insertlines j + 3, "End Sub"
End With


VBA.UserForms.Add (Usf.Name)
Set creationUserForm_Et_listBox_Dynamique = UserForms(UserForms.Count - 1)

End Function

bonne soiree
michel
0
michelxld Messages postés 402 Date d'inscription vendredi 6 août 2004 Statut Membre Dernière intervention 12 octobre 2008 32
17 avril 2006 à 12:47
bonjour

ci joint une petite amélioration pour mon précédent message

tu peux remplacer la ligne

.insertlines j + 2, "If Not ListBox1.ListIndex = -1 Then MsgBox ListBox1"

par

.insertlines j + 2, "If Not " & nomListe & ".ListIndex = -1 Then MsgBox " & nomListe

bon apres midi
michel
0
Rejoignez-nous