Retrieving contents of a Listbox

B

Barry

I'm trying to retrieve the contents of a listbox and place it into a
filename with a .doc extension. I know I have to loop through the
list box and get the contents. I can retrieve the first item with
listbox.text but I'm not quite sure how to retrieve the rest of the
listbox.list and then concatenate everything into a filename. Any
help would be greatly appreciated.


Thanks,

Barry
 
H

Helmut Weber

Hi Barry,
like that:
Dim s As String
Dim i As Integer
With ListBox1
For i = 0 To .ListCount - 1
s = s & .List(1, 0)
' in case of only 1 column
Next
s = s & ".doc"
End With
MsgBox s
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
B

Barry

Thanks for the reply, you have been really helpful.

I am still having problems retrieving all the contents of the Listbox.
The .listcount returns the correct number of rows in the listbox but
the s only ever equals the value displayed at 1 (x3, for 3 items in
the listbox)

So if i have a list box with the contents as follows.

1
2
3
4

The code below will display a msgbox as follows 222.doc, is there
another way to display 1234.doc.

Thanks again and looking forward to your reply.

Barry
 
H

Helmut Weber

Hi Barry,
was my fault, should have been:
s = s & ListBox1.List(i, 0) ' i
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 

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