Hi, I am creating a multi-pick listbox in a userform. The listbox has names
in alphabetical order. I am using the code below to import selected items
into the Word doc. Why does the list of selected items appear in the Word doc
in reverse alpha order? For example, my listbox has 2 choices "Apples" and
"Oranges". If I pick both "Apples" and "Oranges" my Word doc will list the
choices as Oranges and Apples. I'd like the order in the Word doc to be
alphabetical as well. Thanks for any help you can provide!
For i = 1 To Team.ListCount
'..and check whether each is selected
If Team.Selected(i - 1) Then
' If selected, display item in msgbox
ActiveDocument.Bookmarks("Team").Range.InsertBefore Team.List(i - 1)
& " "
End If
Next
Amy,
If you step through your code you will see that you first insert "apples"
before the bookmark range and then you insert oranges before the bookmark
range which is before apples.
You could build a string first and then just insert it at the end of the
code:
Private Sub CommandButton1_Click()
Dim i As Long
Dim myString As String
For i = 1 To Team.ListCount
'..and check whether each is selected
If Team.Selected(i - 1) Then
' If selected, display item in msgbox
myString = myString + Team.List(i - 1) & " "
End If
Next
ActiveDocument.Bookmarks("Team").Range.InsertBefore myString
Me.Hide
End Sub
Or just process the ListCount is reverse order:
Private Sub CommandButton1_Click()
Dim i As Long
For i = Team.ListCount To 1 Step -1
'..and check whether each is selected
If Team.Selected(i - 1) Then
' If selected, display item in msgbox
ActiveDocument.Bookmarks("Team").Range.InsertBefore Team.List(i - 1)
& " "
End If
Next
Me.Hide
End Sub

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Hi, I am creating a multi-pick listbox in a userform. The listbox has
> names in alphabetical order. I am using the code below to import
[quoted text clipped - 13 lines]
> End If
> Next