[英]How to check all files in the folder if modified this month?
我需要对我的代码实施一个条件,其中它检查所有文件是否在代码运行的同一个月被修改。 如何修改此代码以检查月份?
Sub LookForNew()
Dim n As String, msg As String, d As Date
msg = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\TestFolder").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
If msg = "" Then
MsgBox "No new files"
Else
MsgBox msg
End If
Set fso = Nothing
End Sub
请尝试下一个改编代码:
Sub LookForNew()
Dim FSO As Object, fils As Object, fil As Object, msg As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fils = FSO.GetFolder(ThisWorkbook.Path).Files
For Each fil In fils
If Month(fil.DateLastModified) = Month(Date) And _
Year(fil.DateLastModified) = Year(Date) Then
msg = msg & fil.Name & vbTab & _
fil.DateLastModified & vbCrLf
End If
Next fil
If msg = "" Then
MsgBox "No new files"
Else
MsgBox msg
End If
Set FSO = Nothing
End Sub
您要求“所有文件都在同一个月修改”并且您的代码检查创建日期。 我的,检查你问的...
为了避免返回上一年同月修改过的文件,还必须检查年份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.