Q: VBA ListBox

J

Jim Aksel

I have a Windows Form created in VBA within Project. The form contains
ListBox1.
I am trying to read the value of the selected items.

Basically
For i=0 to ListBox1.ListCount-1
if ListBox1.Selected(i) then
I want to know the text of what the list box contains for the selected item
end if
Next i

I see no method or property in the Object Browser that tells me what the
value of the text is in the list box for the selected index.

Seems like there is a better way to to this with a For Each.
The list box is is a multi value select, so the user can select multiple
items. I just want to knock the selected ones off one at a time and then go
do something.
To do that, I need to know the text of what I had when I loaded the list box:

With ListBox1
..AddItem("Text1")
..AddItem(Text2")
.... there are 30 of these as you might suspect....
End With

I will use this with the GetField and SetField functions.

TIA

Jim
 
R

Rod Gill

Hi Jim,

I think the Column property is what you want. EG:

For i=0 to ListBox1.ListCount-1
if ListBox1.Selected(i) then
msgbox Listbox1.Column(column, i)
end if
Next i

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
J

Jim Aksel

So much different than VB.NET ... It's hard to remember all the way back to
VB4 & 6.

Thanks
--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 

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