Reading items in a list box

K

KristyS

Hi!
I am trying to read items that were put into a list box (in Word)and
then take those items and put them into a table in Word at a bookmark.

This is what I have going on the user form:
TextBox
cmdButton
ListBox

The user free-types something into the text box, hits the command
button and the item is added to the list box (I have this working).
From here, I want to be able to read all the items they added to the
list box and send them over to the table I will have in word. I can do
the table part, it is just that middle part of reading the items in the
list box I am having trouble with.

There can be an infinite number of entries in the list box, so do I
need an array of some sort?

If you can think of a better way of "grabbing" the free form info from
the user, let me know. Since there can be many different entries, I
thought this was best. (plus this allows the user to review their
entries and delete one if necessarry. I have another button that allows
them to delete an entry from the list.)

Thanks!
Kristy
 
K

KristyS

Thanks. I got this to work a few days ago, but I did it differently. I
wasn't able to get your code to work. This is what I did:

Dim s As String
Dim i As Integer

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="tRetentionTime"
'Read through list box and insert items into table
With lstLNumberList
For i = 0 To .ListCount - 1
'read items in list and put a space between them
s = s & .List(i, 0) & " "
Selection.TypeText Text:=s
'Clears the variable to accept the next item in the
list
s = ""
'Moves to next line in table
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Next
End With
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
 

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