Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Listbox Strings to word (https://www.askmehelpdesk.com/showthread.php?t=394252)

  • Sep 7, 2009, 09:51 AM
    esperanto234
    Listbox Strings to word
    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!
  • Sep 7, 2009, 10:14 AM
    ScottGem

    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.
  • Sep 7, 2009, 11:15 AM
    esperanto234
    Quote:

    Originally Posted by ScottGem View Post
    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.
  • Sep 7, 2009, 11:23 AM
    ScottGem

    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.
  • Sep 7, 2009, 11:29 AM
    esperanto234
    Quote:

    Originally Posted by ScottGem View Post
    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

  • All times are GMT -7. The time now is 10:18 PM.