Open the last file in a folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would be very grateful for some code to open the last file in a folder.
They are date stamped but the date might not be known!! So it really has to
be the last one no matter what date it is!
 
Hi Spike,

This is using Microsoft Scripting Runtime library (fileSystemObject)


Function ShowLastfile(folderspec As String) As String
Dim fso, f, f1, fc
Dim sFileName As String
Dim dDate As Date

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
If dDate < f1.datecreated Then
dDate = f1.datecreated
sFileName = f1.Name
End If
Next
ShowLastfile = sFileName
End Function

Sub test()
MsgBox ShowLastfile("C:\Temp\")
End Sub

Regards
Jean-Yves
 
Back
Top