2012-09-26 3 views
2

파일 이름, 크기, 경로 및 날짜를 ​​반환하는 코드 조각이 있습니다. if 문을 사용하면 X보다 큰 날짜가 표시됩니다. 이처럼Excel에서 파일의 datemodified 필터링 방법

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 
+0

'날짜보다'당신은 특정 날짜 이후의 날짜를 의미합니까 ? –

+0

예, 예 : dd/mm/yyyy hh : mm : ss – user648244

답변

0

:

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 
+0

나는 그것을 시도했지만 시간도 고려하고 싶다. 내가 12/12/2005 00:00:00 일 경우, 그걸 – user648244

+0

이라고 불평하고, 'Dim myDateTime as Variant'를 시도하고 'myDateTime = Format ("12/12/2005 00:00:00", "MM/DD/YYYY hh : mm : ss ")' – Jook

0

왜 사용하는 대신 끝에 필터가 아닌 IF : 당신이 말하는

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 
관련 문제