如何使用 VBA 检查文本文件的时间戳 [英] How to check timestamp of a text file using VBA

查看:14
本文介绍了如何使用 VBA 检查文本文件的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

VBA中有什么函数可以救我吗?

Is there any function in VBA that can save me?

推荐答案

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

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.

编辑

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

这篇关于如何使用 VBA 检查文本文件的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆