P
Pavu
Hi all
How do I fill a listbox in a userform with data from a text file?
My text file has semi colon as column delimiter, data looks like this:
Choice1;Element1;Option1
My ListBox has three columns.
I have tried the code below but I keep getting errors when trying to add
items from my list.
Could somebody help please?
Private Sub UserForm_Initialize()
dim fso, txtfile, tbl()
Dim MyList As New Collection
Set fso = CreateObject("Scripting.FilesystemObject")
Set txtfile = fspenTextFile ("C:\test.txt", 1)
i = 0
Do while txtfile.AtEndOfStream <> True
ReDim Preserve tbl(i)
tbl(i) = Split(txtfile.Readline,";",vbTextCompare)
MyList.Add tbl(i)
i = i +1
Loop
txtfile.Close
Set fso = Nothing
For y = 1 To MyList.Count
Listbox.AddItem MyList(y)
Next y
End Sub
TIA
Patrick
How do I fill a listbox in a userform with data from a text file?
My text file has semi colon as column delimiter, data looks like this:
Choice1;Element1;Option1
My ListBox has three columns.
I have tried the code below but I keep getting errors when trying to add
items from my list.
Could somebody help please?
Private Sub UserForm_Initialize()
dim fso, txtfile, tbl()
Dim MyList As New Collection
Set fso = CreateObject("Scripting.FilesystemObject")
Set txtfile = fspenTextFile ("C:\test.txt", 1)
i = 0
Do while txtfile.AtEndOfStream <> True
ReDim Preserve tbl(i)
tbl(i) = Split(txtfile.Readline,";",vbTextCompare)
MyList.Add tbl(i)
i = i +1
Loop
txtfile.Close
Set fso = Nothing
For y = 1 To MyList.Count
Listbox.AddItem MyList(y)
Next y
End Sub
TIA
Patrick