How to check timestamp of a text file using VBA

前端 未结 1 1080
既然无缘
既然无缘 2020-12-20 18:40

I\'m trying to write a code in Excel 2003 VBA (Windows XP) to find out if outside TXT file has different timestamp, so I can \'import\' it if it changed.

Is there an

相关标签:
1条回答
  • 2020-12-20 19:05

    I think you want the modified date. If yes, then see this

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

    The format of the date and time displayed is based on the locale 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
    
    0 讨论(0)
提交回复
热议问题