Ik gebruik vba in word en wil graag een combobox vullen met gegevens uit een bestand. Via een listbox wil ik een keuze kunnen maken uit deze gegevens. Ik heb de volgende code al gemaakt maar ik krijg niets te zien in een het userform. Wat doe ik verkeerd
#CODE#
Sub UserForm_Initialize()
'Add list entries to combo box. The value of each
'entry matches the corresponding ListIndex value
'in the combo box.
'Groep 7
Dim a() As String
Dim n As Integer
Dim o As Integer
o = -1
Do
n = n + 1
S = System.PrivateProfileString("C:\Tweestroom\leerlingen.txt", "Plaatsen", n)
If Len(S) Then o = o + 1: a(o) = S
Loop While Len(S)
ReDim Preserve a(o)
ComboBox1.List() = a
'Use drop-down list ComboBox1
ComboBox1.Style = fmStyleDropDownList
'Combo box values are ListIndex values
ComboBox1.BoundColumn = 0
'Set combo box to first entry
ComboBox1.ListIndex = 0
End Sub
Sub ComboBox1_Click()
Dim a() As Variant
Dim n As Integer
Dim o As Integer
o = 0
Do
n = n + 1
S = System.PrivateProfileString("C:\Tweestroom\leerlingen.txt", "Groep1", n)
If Len(S) Then o = o + 1: a(o) = S
Loop While Len(S)
ReDim Preserve a(o)
ComboBox1.Text() = S
End Sub
#END CODE#
De inhoud van het tekstbestand is:
[Groep1]
1=Jos
2=Henk
[Groep2]
1=Karel
2=Piet
Wie kan mij helpen.
Dank Jos
#CODE#
Sub UserForm_Initialize()
'Add list entries to combo box. The value of each
'entry matches the corresponding ListIndex value
'in the combo box.
'Groep 7
Dim a() As String
Dim n As Integer
Dim o As Integer
o = -1
Do
n = n + 1
S = System.PrivateProfileString("C:\Tweestroom\leerlingen.txt", "Plaatsen", n)
If Len(S) Then o = o + 1: a(o) = S
Loop While Len(S)
ReDim Preserve a(o)
ComboBox1.List() = a
'Use drop-down list ComboBox1
ComboBox1.Style = fmStyleDropDownList
'Combo box values are ListIndex values
ComboBox1.BoundColumn = 0
'Set combo box to first entry
ComboBox1.ListIndex = 0
End Sub
Sub ComboBox1_Click()
Dim a() As Variant
Dim n As Integer
Dim o As Integer
o = 0
Do
n = n + 1
S = System.PrivateProfileString("C:\Tweestroom\leerlingen.txt", "Groep1", n)
If Len(S) Then o = o + 1: a(o) = S
Loop While Len(S)
ReDim Preserve a(o)
ComboBox1.Text() = S
End Sub
#END CODE#
De inhoud van het tekstbestand is:
[Groep1]
1=Jos
2=Henk
[Groep2]
1=Karel
2=Piet
Wie kan mij helpen.
Dank Jos
