I have part of code which goes over the files of a folder and assigns a number to them. These files are zip files generated with a "run number-date-time.7z" name format. Their numbers and date/time stamps are in order. It is important for my application that the files are read by the Dir()-loop in the correct order also but that does not happen (see attached image).
Can someone help me understand why this is and how to correct it?
Any help is much appreciated!
Sub Test()
Dim sPath As String, archiveFiles() As String
Dim wbTarget As Workbook
Dim rSrc As Range
Dim rDst As Range
targetWorkbook = ThisWorkbook.Name
sPath = ThisWorkbook.Path
folderName = "D:\New folder\Archives"
'Look in folder for archive files
If Right(folderName, 1) <> "\" Then
folderName = folderName & "\"
End If
j = 0
archiveFile = Dir(folderName & "*.7z")
Do Until archiveFile = vbNullString
ReDim Preserve archiveFiles(j + 1)
archiveFiles(j) = folderName & "\" & archiveFile
archiveFile = Dir()
j = j + 1
Loop
End Sub