Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在excelvba中过滤文件的修改日期_Excel_Vba - Fatal编程技术网

如何在excelvba中过滤文件的修改日期

如何在excelvba中过滤文件的修改日期,excel,vba,Excel,Vba,我有一个返回文件名、大小、路径和日期的代码段。如何放置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 myS

我有一个返回文件名、大小、路径和日期的代码段。如何放置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
像这样:

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

如果,为什么不在结尾处过滤而不是使用

Option Explicit
Sub FilterbyDate()
    Dim ws As Worksheet
    Dim rng As Range
    Dim frng As Range
    Set ws = Sheets("Sheet1")
    ' Remove any previous filters
    ws.AutoFilterMode = False
    ' Specify range to be filtered
    Set rng = ws.Range("xx")

    With rng
        ' Filter data by date:
        ' where field is the column number with your dates and
        ' change the date criteria to what you desire
        .AutoFilter Field:=1, Criteria1:=">dd/mm/yyyy hh:mm:ss"
        ' Define the filtered range;
        ' You could then copy it to a new sheet
        ' deleting original so you're only left
        ' with the data you want
         Set frng = .SpecialCells(xlCellTypeVisible)
        ' frng.Copy
    End With
End Sub

如果
,为什么不在结尾处过滤而不是使用

Option Explicit
Sub FilterbyDate()
    Dim ws As Worksheet
    Dim rng As Range
    Dim frng As Range
    Set ws = Sheets("Sheet1")
    ' Remove any previous filters
    ws.AutoFilterMode = False
    ' Specify range to be filtered
    Set rng = ws.Range("xx")

    With rng
        ' Filter data by date:
        ' where field is the column number with your dates and
        ' change the date criteria to what you desire
        .AutoFilter Field:=1, Criteria1:=">dd/mm/yyyy hh:mm:ss"
        ' Define the filtered range;
        ' You could then copy it to a new sheet
        ' deleting original so you're only left
        ' with the data you want
         Set frng = .SpecialCells(xlCellTypeVisible)
        ' frng.Copy
    End With
End Sub

当你说“日期更大”时,你是指某个日期之后的日期吗?是的,例如dd/mm/yyyy hh:mm:ss当你说“日期更大”时,你是指某个日期之后的日期吗?是的,例如dd/mm/yyyy hh:mm:ssI我试过了,但我也想考虑时间。如果我做的是2005年12月12日00:00:00,那么请尝试将myDateTime设置为变量和格式(“2005年12月12日00:00:00”,“MM/DD/YYYY hh:MM:ss”)
我尝试过它可以工作,但我也想考虑时间。如果我在2005年12月12日00:00:00执行此操作,则会将其分解,然后尝试将myDateTime设置为变量和格式(“12/12/2005 00:00:00”,“MM/DD/YYYY hh:MM:ss”)