Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  Answer this Question    Ask about Visual Basic    Ask about another Subject  
 

esperanto234
Sep 7, 2009, 09:51 AM
Hi, Im using alistbox to insert names in a word document, im' 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 theres 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