Sorting File names
Dear All,
I get file names to an excel sheet from a folder, using the below macro. I tried to sort them in ascending order. but I have not sorted them in the correct order. please can anyone solve this issue?
Correct oder : 1-1.pdf, 1-2.pdf, 1-3.pdf ............... 1-10.pdf, 1-11.pdf......1-20.pdf..
After getting to the excel sheet: 1-1.pdf, 1-10.pdf, 1-11.pdf, 1-20.pdf........
My VBA Code :
Sub Get_Old_File_Name()
Dim myPath As String
Dim myFile As String
Dim r As Long
myPath = "C:\Users\User\Desktop\Maling Payadvice\NVQ\PaySlips"
myFile = Dir(myPath & "*.*")
If myFile = "" Then
MsgBox " No Files in the Folder"
Else
r = 4
Do While myFile <> ""
Cells(r, 5).Value = myFile
r = r + 1
myFile = Dir
Loop
MsgBox "Completed"
End If
End Sub
|