The VBA FileDateTime function returns a String, containing the last modified date and time of a supplied file.
The syntax of the function is:
Where the PathName argument provides the path and file name of the file that you want details of.
In the example below, the VBA FileDateTime function is used to return the last modified date and time for the file C:\Users\John\Documents\data.txt.
' Return the last modified date of the file data.txt.Dim lastMod As String
lastMod = FileDateTime( "C:\Users\John\Documents\data.txt" )
' lastMod is now equal to the String "1/20/2016 4:52:03 PM".
After running the above VBA code, the variable lastMod is equal to the String "1/20/2016 4:52:03 PM", which is the date and time that the supplied file was last modified.
If the PathName that is supplied to the VBA FileDateTime function does not relate to an existing file, you will get the error: