LISTING FILES IN FOLDER - INCORRECT ORDER
Hi
I am trying to create a list of filenames in my folder (that are copied in to column A). I am using the code below which sort of works however outputs the files in a different order as to how they are in my folder. I need them in the EXACT same order. I am assuming the Excel is listing them 'alphabetically' and using the numbers at the end of the files to sort? Is there a way of sorting just as the files are? Or could I add a 1,2,3,4.... prefix to each file before copying across to my Excel sheet?
E.g. This is the order in my folder
File1 in my folder is Trees8.pdf
File2 in my folder is Leaves9.pdf
File3 in my folder is Bears10.pdf
File4 in my folder is Sky11.pdf
File5 in my folder is Water12.pdf and so on
However the output listed in Column A in Excel is :
Bears10.pdf
Sky11.pdf
Water12.pdf
Trees8.pdf
Leaves9.pdf
Code:
Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\Users\branston"
MyFile = Dir(MyFolder & "\*.*")
a = 0
Do While MyFile <> ""
a = a + 1
Cells(a, 1).Value = MyFile
MyFile = Dir
Loop
End Sub