gpt4 book ai didi

excel - 用于验证文件上次修改时间的宏

转载 作者:行者123 更新时间:2023-12-03 02:03:37 24 4
gpt4 key购买 nike

我见过一些非常相似的问题,但没有一个能提供我正在寻找的答案。其中一些没有得到答复。

我有一个 VBA 宏,它通过搜索文件并验证文件的创建时间来验证在特定日期(在本例中是昨天)创建的所有文件。由于该宏是在互联网上找到的,我不确定这些对象是如何工作的。

我想知道是否有办法更改 fill.DateCreated 以获得类似的内容,但宏不会检查文件创建时的日期,而是会验证文件何时被修改。起初看起来很简单,但现在我真的很难做到这一点。谁能帮我解决这个问题吗?

Sub VerifyNewFiles()

Dim n As String, msg As String, d As Date
msg = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\Users\Desktop\").Files

For Each fil In fils
n = fil.Name
d = fil.DateCreated

If d >= Date - 1 Then
msg = msg & n & vbTab & d & vbCrLf
End If
Next fil

MsgBox msg

Set fso = Nothing

End Sub

最佳答案

f.DateLastModified 可能适合您。

如果您通过 VBE 中的工具 -> 引用添加对 Microsoft Scripting Runtime 库的引用,您可以提前绑定(bind)对象并获得它们的智能感知。

Sub VerifyNewFiles()

Dim fName As String, msg As String, fDate As Date


Dim fso As New FileSystemObject
Set fils = fso.GetFolder("C:\Users\" & Environ$("Username") & "\Desktop\").Files

Dim fil As File
For Each fil In fils

fName = fil.Name
fDate = fil.DateLastModified

If fDate >= Date - 1 Then msg = msg & fName & vbTab & fDate & vbCrLf
Next fil

MsgBox msg

Set fso = Nothing
End Sub

将库引用(Microsoft Scripting Runtime)添加到您的项目后,您可以打开对象浏览器F2并选择库来探索它

enter image description here

关于excel - 用于验证文件上次修改时间的宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26239766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com