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

时间:2012-05-30 20:03:33

标签: vba excel-vba timestamp excel-2003 excel

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

VBA中是否有任何可以救我的功能?

1 个答案:

答案 0 :(得分:11)

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

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

显示的日期和时间格式取决于系统的区域设置。

修改

使用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