Problem with Excel list box

K

Keith

Hello, I am trying to learn how to work with the list of
informtion in a listbox. I have added the list using
AddItem. Now I want to print that list to file. The
following code does not work, and has my notes. I would
appreciate any suggestions on how to make the print
statement work, but also how to move data into this two-
column listbox list.
Thank you

Keith


var3 = ListBox1.ListCount


Close #1
i = 0
Open "c:\test\temp.txt" For Output As #1
For i = 0 To var3 - 1 'Each In ListBox1
'i = i + 1

Print #1, i
'Print #1, ListBox1(i).Value ' not accepted at run
time
'Print #1, ListBox1(i, 1).Value ' not accepted at run
time
'Print #1, ListBox1(i, 0).Value ' not accepted

'Print #1, ListBox1(i).Text


Next i
Close #1
 
P

Patrick Molloy

NOT
ListBox1(i).Value

With Listbox1
For i = 0 to .ListCount -1
Print #1, .List(i)
Next
Close
End With


'' note the "." before ListCount and also List
 
K

K Dales

You need to use the .Column property, e.g:

Print #1, ListBox1.Column(0,i) ' Prints row i-1, column 1

Note that the column and row values are 0 based; the first one is numbered 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top