Populate 2 column listbox using outlook vba (1 Viewer)

aman

Registered User.
Local time
Today, 13:16
Joined
Oct 16, 2008
Messages
1,250
Hi Guys,

I am thinking of a way to populate 2 column listbox based on data stored in a notepad (on the network). I don't want this to be hard coded so if anyone wants to change the options then just make changes i notepad and listbox will get updated automatically.

Can anyone please help me in this?

Thanks
 

Ranman256

Well-known member
Local time
Today, 16:16
Joined
Apr 9, 2015
Messages
4,337
you don't populate combo/listbox with notepad, you use a table/query.

if you mean , take the data from the notepad and put into the table source, then you could just COPY/PASTE
or
you could use a TransferText command , but the data must be in the correct format.

you did not supply the format/example.
 

aman

Registered User.
Local time
Today, 13:16
Joined
Oct 16, 2008
Messages
1,250
I am working on Outlook VBA so I have a userform and there is 2 column listbox on it. I want to store data in a .csv file or any other file that will reside on the network and want to write a piece of code that will store data in a listbox from that particular file on the network.

What is the best way to do it? Any help will be much appreciated.

Thanks
 

aman

Registered User.
Local time
Today, 13:16
Joined
Oct 16, 2008
Messages
1,250
I got the following code but not sure how to make it working for multicolumn listbox . My text file stores data as below:
1,A
2,B
3,C
4,D

I need to make 1st column of the listbox hidden so that users can see A,B,C,D in the listbox .
Code:
Private Sub UserForm_Initialize()
  Dim fn As String, ff As Integer, txt As String
    fn = "C:\Users\drcp\Documents\keywords.txt" '< --- .txt file path
    txt = Space(FileLen(fn))
    ff = FreeFile
    Open fn For Binary As #ff
    Get #ff, , txt
    Close #ff

 Dim myArray() As String
  'Use Split function to return a zero based one dimensional array.
  myArray = Split(txt, vbCrLf)
  'Use .List method to populate listbox.
  ListBox1.List = myArray
lbl_Exit:
  Exit Sub

End Sub
 

Users who are viewing this thread

Top Bottom