Sorted list of filenames in a folder in VBA?
Is there a way to get a sorted list of filenames in VBA? So far I have arrived at
Dim fso As Object
Dim objFolder As Object
Dim objFileList As Object
Dim vFile As Variant
Dim sFolder As String
sFolder = "C:\Docs"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(sFolder)
Set objFileList = objFolder.Files
For Each vFile In objFileList
' do something '
Next vFile
but it is very important to make sure that the processing order of the for loop is determined by the file names ...
Any help is appreciated!
+2
a source to share
3 answers
Load a VBA sort routine such as this one: Recursive quicksort
Populate the array with filenames and just select as shown here .
+3
a source to share
It looks like you can do it using ADODB.RecordSet
. It's a bit heavy duty, but here's the link you should start with.
+1
a source to share
The order is arbitrary.
When you go objFileList
, add files to the array, then sort the array .
+1
a source to share