The VBA FileDateTime Function

Related Functions:
VBA FileLen
VBA GetAttr

Description

The VBA FileDateTime function returns a String, containing the last modified date and time of a supplied file.

The syntax of the function is:

FileDateTime( PathName )

Where the PathName argument provides the path and file name of the file that you want details of.


VBA FileDateTime Function Example

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.


VBA FileDateTime Function Error

If the PathName that is supplied to the VBA FileDateTime function does not relate to an existing file, you will get the error:

Run-time error '76': Path not found

VBA Run Time Error 76 Message Box