如何使用VBA检查文本文件的时间戳

MrB*_*MrB 7 excel vba timestamp excel-2003 excel-vba

我正在尝试在Excel 2003 VBA(Windows XP)中编写代码,以确定外部TXT文件是否具有不同的时间戳,因此如果更改,我可以"导入"它.

VBA中有什么功能可以救我吗?

Sid*_*out 11

我想你想要修改日期.如果是,那么看看这个

Debug.Print FileDateTime("C:\Sample.txt")
Run Code Online (Sandbox Code Playgroud)

显示的日期和时间格式基于系统的区域设置.

编辑

运用 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
Run Code Online (Sandbox Code Playgroud)