gpt4 book ai didi

excel - 如何在excel vba中过滤文件的修改日期

转载 作者:行者123 更新时间:2023-12-04 21:06:55 26 4
gpt4 key购买 nike

我有一个返回文件名、大小、路径和日期的代码片段。如何放置 if 语句以便显示大于 X 的日期?

    Dim irow
Sub ListFiles()
irow = 11
Call ListMyFiles(Range("C7"), Range("C8"))
End Sub

Sub ListMyFiles(mySourcePath, IncludeSubfolders)
Set MyObject = New Scripting.FileSystemObject
Set mySource = MyObject.GetFolder(mySourcePath)
On Error Resume Next
For Each myFile In mySource.Files
iCol = 2
Cells(irow, iCol).Value = myFile.Path
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.Name
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.Size
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.DateLastModified
irow = irow + 1
Next
If IncludeSubfolders Then
For Each mySubFolder In mySource.SubFolders
Call ListMyFiles(mySubFolder.Path, True)
Next
End If
End Sub

最佳答案

像这样:

Dim myDate as Date
myDate = "12.02.1985"

For Each myFile In mySource.Files
if myFile.DateLastModified > myDate then
iCol = 2
Cells(irow, iCol).Value = myFile.Path
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.Name
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.Size
iCol = iCol + 1
Cells(irow, iCol).Value = myFile.DateLastModified
irow = irow + 1
end if
Next

关于excel - 如何在excel vba中过滤文件的修改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12605295/

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