Microsoft Office Tutorials and References
In Depth Information
Creating a List of Files That Reside in a Directory
'Add a new workbook with one sheet¶
Workbooks.Add xlWorksheet¶
'Put the headers¶
With Range("A1").Resize(1, 5)¶
.Value = Array("Full path", "File name", "Path", _¶
"Size (kB)", "Date created")¶
.Font.Bold = True¶
End With¶
'Loop through the found files¶
For i = 1 To .FoundFiles.Count¶
'clear File variable¶
Set File = Nothing¶
On Error Resume Next¶
Set File = FSO.GetFile(.FoundFiles(i))¶
On Error GoTo 0¶
If Not File Is Nothing Then¶
'Not File Is Nothing is code for "the file exists"¶
With Cells(i + 1, 1)¶
'Put the variables desired¶
'Full path¶
.Value = File.Path¶
'Name only¶
.Offset(, 1).Value = File.Name¶
'Path¶
.Offset(, 2).Value = File.ParentFolder¶
'Size in KB¶
.Offset(, 3).Value = File.Size / 1024¶
'Date created¶
.Offset(, 4).Value = File.DateCreated¶
'Other available properties can be included by¶
'removing the appostrophe in front of the line¶
'that should be used.¶
'.Offset(,5).Value = File.Attributes¶
'.Offset(,6).Value = File.Datelastaccessed¶
'.Offset(,7).Value = File.Datelastmodified¶
'.Offset(,8).Value = File.Drive¶
'.Offset(,9).Value = File.Shortname¶
'.Offset(,10).Value = File.Shortpath¶
'.Offset(,11).Value = File.Type¶
End With¶
End If¶
Next i¶
End With¶
'Change the width of column A¶
Range("A:A").EntireColumn.ColumnWidth = 50¶
'Format column D (Size)¶
Range("D:D").NumberFormat = "#,##0.00"¶
'Format column E (Date)¶
Range("E:E").NumberFormat = "mmm dd, yy"¶
Exl
Search JabSto ::




Custom Search