PDA

View Full Version : Listbox Strings to word


esperanto234
Sep 7, 2009, 09:51 AM
Hi, Im using alistbox to insert names in a word document, I'm using the following code but it only inserts the first ITEM on the list.


Code:
Dim strList1 As String
strList1 = ListBox1.List(ListBox1.ListIndex)
ActiveDocument.Bookmarks("p91").Range.Text = strList1

My question is: How can I do to insert ALL items in the listbox in word. I need them to be separated by comas and the last one by "and". Ex:

ITEM1, ITEM2, ITEM3 and ITEM4.

ITEM1, ITEM2 and ITEM3.

ITEM1, ITEM2 and ITEM5.


Of course, if there's only 1 item I need the "and" to be deleted. Ex:

ITEM1

THANK YOU VERY VEERY MUCH!

ScottGem
Sep 7, 2009, 10:14 AM
If you are using a multi-select listbox, then you need to loop through the ItemsSelected collection. When the multi-select property is set to yes, the control itself does not store a value.

esperanto234
Sep 7, 2009, 11:15 AM
If you are using a multi-select listbox, then you need to loop through the ItemsSelected collection. when the multi-select property is set to yes, the control itself does not store a value.

Could you please help me with the entire code? I'm using a multi-select listbox.

ScottGem
Sep 7, 2009, 11:23 AM
I don't know the exact code for VB. I can give you an example for Access VBA, but I don't know if that will help. Try googling VB Multi-Select listbox.

esperanto234
Sep 7, 2009, 11:29 AM
I don't know the exact code for VB. I can give you an example for Access VBA, but I don't know if that will help. Try googling VB Multi-Select listbox.

Thanks anyway for your help.:D