Sorted list of file names in a folder in VBA?

Posted by Karsten W. on Stack Overflow See other posts from Stack Overflow or by Karsten W.
Published on 2010-05-11T14:32:02Z Indexed on 2010/05/11 14:44 UTC
Read the original article Hit count: 479

Filed under:
|

Is there a way to get a sorted list of file names of a folder in VBA? Up to now, I 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 crucial to be sure the processing order of the for loop is determined by the file names...

Any help appreciated!

© Stack Overflow or respective owner

Related posts about vba

Related posts about file