Khimono
06-10-2016, 07:29 AM
Hi all,
I'm looking for some help finishing the code below. It's a macro to populate a list of files in a folder, currently W:\test and automatically hyperlink to the files. It's working as intended at the moment, apart from one issue I can't solve.
It automatically populates the list in alphabetical order. I'd like the list to generate in order by date created, with the newest file at the top of the list.
Could someone help me modify the code below to solve this?
Thanks
Sub Memo()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("W:\test")
i = 1
For Each objFile In objFolder.Files
Range(Cells(i + 11, 5), Cells(i + 11, 5)).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
objFile.Path, _
TextToDisplay:=objFile.Name
i = i + 1
Next objFile
End Sub
I'm looking for some help finishing the code below. It's a macro to populate a list of files in a folder, currently W:\test and automatically hyperlink to the files. It's working as intended at the moment, apart from one issue I can't solve.
It automatically populates the list in alphabetical order. I'd like the list to generate in order by date created, with the newest file at the top of the list.
Could someone help me modify the code below to solve this?
Thanks
Sub Memo()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("W:\test")
i = 1
For Each objFile In objFolder.Files
Range(Cells(i + 11, 5), Cells(i + 11, 5)).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
objFile.Path, _
TextToDisplay:=objFile.Name
i = i + 1
Next objFile
End Sub