Ok. Please add this UDF :
Function GetFileDateLastModified(strFile)
GetFileDateLastModified = CreateObject("Scripting.FileSystemObject").GetFile(strFile).DateLastModified
End Function
Function GetFileDateCreated(strFile)
GetFileDateCreated = CreateObject("Scripting.FileSystemObject").GetFile(strFile).DateCreated
End Function
And then change this line into :
'LMD = FileDateTime(MyPath & MyFile)
LMD = GetFileDateCreated(MyPath & MyFile)
As a note, there could be unexpected desired on how Windows treat the file creation and modification date.
Lets say a file "ABC.TXT" is created on 1 Jan 2021, and it has modified several times and the last modification date is 15 Jan 2021.
Now, as long as the file stay in the folder it is placed, then it will be working as expected -> the modification date will always bigger than creation date
But if this file "ABC.TXT" is copied to another folder, then for this copied file, the modification date will be the same but the creation date will be set as the current time the file being copied, so for this copied file, the creation date will be bigger than modification date.
The macro above just get the creation date reported by Operating System (you can check this by examining the file from Windows Explorer). Should this not what you expected, you need to change the code to fulfill your expectation.
Bookmarks