This code populate a ListBox with the file names of a specific folder
Dim DIRECTORY As String
DIRECTORY = Dir(myPath & "\*.xlsx", vbNormal)
Do Until DIRECTORY = ""
ListBox1.AddItem DIRECTORY
DIRECTORY = Dir()
Loop
But I want a sorted list.
How can I sort the files firstly and then populate the ListBox.
btw sorting a listbox is (as I know) a long procedure.
A
ListBoxdoes not have a built in sort capability. You will need to roll your own.The basic idea is to get the list data into an array, sort the array, and then put the data back in to the list. There are many good references avaliable for sorting VBA arrays.
Unless you have a very large number of files, a simple sort will probably suffice. Try This