How to check text file timestamp using VBA

I am trying to write code in Excel 2003 VBA (Windows XP) to find out if an external TXT file has a different timestamp, so I can "import" it if it has changed.

Is there any function in VBA that can save me?

+6
source share
1 answer

I think you want to change the date. If so, see. This

Debug.Print FileDateTime("C:\Sample.txt") 

The format of the displayed date and time is based on the language settings of your system.

Edit

Using FileSystemObject

 Option Explicit Sub Sample() Dim oFS As Object Dim sFile As String sFile = "C:\MyFile.txt" Set oFS = CreateObject("Scripting.FileSystemObject") '~~> Created Date Debug.Print "Created Date : "; oFS.GetFile(sFile).DateCreated '~~> Modified Date Debug.Print "Modified Date : "; oFS.GetFile(sFile).Datelastmodified Set oFS = Nothing End Sub 
+10
source

Source: https://habr.com/ru/post/917048/


All Articles