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

查看:272
本文介绍了如何使用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天全站免登陆