Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

excel - How to check timestamp of a text file using VBA

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 any function in VBA that can save me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...