I have a lot of measurement files as csv-files and I want to merge them next to each other in one excel file. My VBA code works fine except the fact that it kind of sorts the file names in the wrong alphabetical order. When I look in the Explorer I get my files in the proper order:
But when I either use the dir command in the command line or use VBA code to list/sort the file names:
Sub Dateien_eines_Ordners_Auflisten()
Dim lngZeile As Long
Dim objFileSystem As Object
Dim objVerzeichnis As Object
Dim objDateienliste As Object
Dim objDatei As Object
Set objFileSystem = CreateObject("scripting.FileSystemObject")
Set objVerzeichnis = objFileSystem.GetFolder("D:\Dokumente\Masterarbeit-Bertrandt\Versuche_Prüfstand\Messungen\150RPM\")
Set objDateienliste = objVerzeichnis.Files
lngZeile = 1
For Each objDatei In objDateienliste
If Not objDatei Is Nothing Then
ActiveSheet.Cells(lngZeile, 1) = objDatei.Name
lngZeile = lngZeile + 1
End If
Next objDatei
End Sub
I get the folling output:
How can I sort the files like the Explorer does? And why is there a difference in the sorting?
Thanks a lot for any help!