Home » excel » excel – Check last saved date on all CSV files in a folder

excel – Check last saved date on all CSV files in a folder

Posted by: admin May 14, 2020 Leave a comment

Questions:

Pretty simple question really, I suppose. How can I amend the below so that rather than looking at LOI.CSV it looks at all .CSV files in the Intraday Folder?

LastSaved = FileDateTime("W:\Settlements\Intraday\LOT.csv")

If LastSaved < Date Then
  MsgBox ("The current day file for LOI was last saved " & LastSaved)
End If
How to&Answers:

Try this

Const sPath As String = "W:\Settlements\Intraday\"

Sub LoopThroughFilesInAFolder()
    Dim StrFile As String

    StrFile = Dir(sPath & "\*.Csv")

    Do While Len(StrFile) > 0
        Debug.Print FileDateTime(sPath & "\" & StrFile)
        '~~> Rest of the code here
        StrFile = Dir
    Loop
End Sub