×
×לי
Hi!
I have found a function that imports a list of file names with its last
modification date (www.exceltip.com) and I have modified it so only files
with *.res extention will be imported. I want also to import only files that
was modified in the last 2 days but it not worked (see the code below). the
date is in the format of: dd/mm/yyyy hh:mm.
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As
Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Dim t As Long
Dim s As Date
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
s = Now()
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
t = s - FileItem.DateLastModified
If Right(FileItem.Name, 3) = "res" And t < 2 Then
Cells(r, 1).Formula = FileItem.Name
Cells(r, 2).Formula = FileItem.DateLastModified
End If
r = r + 1 ' next row number
Next FileItem
Columns("A:B").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
I will be happy to understand what is wrong with it.
Thanks in advance
Eli
I have found a function that imports a list of file names with its last
modification date (www.exceltip.com) and I have modified it so only files
with *.res extention will be imported. I want also to import only files that
was modified in the last 2 days but it not worked (see the code below). the
date is in the format of: dd/mm/yyyy hh:mm.
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As
Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Dim t As Long
Dim s As Date
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
s = Now()
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
t = s - FileItem.DateLastModified
If Right(FileItem.Name, 3) = "res" And t < 2 Then
Cells(r, 1).Formula = FileItem.Name
Cells(r, 2).Formula = FileItem.DateLastModified
End If
r = r + 1 ' next row number
Next FileItem
Columns("A:B").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
I will be happy to understand what is wrong with it.
Thanks in advance
Eli