How to sort a ListBox on a UserForm in Word VBA?

I have a list of files which are insterted as Sub-Documents in a Master Document.  The file names are read into a ListBox on a UserForm.  However, they appear in the ListBox in Created Date order.  There doesn't seem to be a "Sort By" property on the ListBox, and there doesn't seem to be a Sort Method for the ListBox.
At the moment, I have to ask the end user to assemble the final order by selecting one at a time and building up the final order in a second ListBox on the same UserForm  -  OK if there are only 10 or a dozen sub-documents, but I know there's one coming up with over 100....!
Anyone have any ideas, please?
(Reasonable experience of VBA in Access and Excel, but not quite so good in Word).
All help gratefully received...!

Ed
jocktherockAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You need to sort the list yourself

Option Explicit

Private Sub CommandButton1_Click()
    Dim strArray() As String
    Dim i As Integer
    ReDim strArray(ListBox1.ListCount - 1)
    For i = 0 To ListBox1.ListCount - 1
        strArray(i) = ListBox1.List(i)
    Next i
    DoSort strArray()
    ListBox1.List = strArray
End Sub

Function DoSort(ByRef sortarray() As String)
Dim i As Integer
Dim j As Integer
Dim strTemp As String
    For i = 0 To UBound(sortarray())
        For j = 0 To UBound(sortarray())
            If sortarray(i) < sortarray(j) Then
                strTemp = sortarray(i)
                sortarray(i) = sortarray(j)
                sortarray(j) = strTemp
            End If
        Next j
    Next i
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jocktherockAuthor Commented:
Excellent!  Worked first time!  I had tried passing the List to an Array, but couldn't get any further than that....!
And the solution came back very rapidly.
Many, many thanks!


Ed
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.