I would like to open the newest *.csv* file in a directory
I have found one particular VBE solution, but it unfortunately does not work in OO
http://spreadsheetpage.com/index.php/ti ... directory/
probably because of some syntax. I tried my best, but I could not make it work by myself.
Could anybody help me out to make this code to work under OO ??
Code: Select all
Function NewestFile(Directory, FileSpec)
REM Returns the name of the most recent file in a Directory
REM That matches the FileSpec (e.g., "*.csv").
REM Returns an empty string if the directory does not exist or
REM it contains no matching files
Dim FileName As String
Dim MostRecentFile As String
Dim MostRecentDate As Date
If Right(Directory, 1) <> "\" Then Directory = Directory & "\"
FileName = Dir(Directory & FileSpec, 0)
If FileName <> "" Then
MostRecentFile = FileName
MostRecentDate = FileDateTime(Directory & FileName)
Do While FileName <> ""
If FileDateTime(Directory & FileName) > MostRecentDate Then
MostRecentFile = FileName
MostRecentDate = FileDateTime(Directory & FileName)
End If
FileName = Dir
Loop
End If
NewestFile = MostRecentFile
MsgBox(MostRecentFile,0,"MostRecentFile")
End Function
many thanks for your help
with friendly regards
Jozef