write at exceltoexplore@gmail.com : Report Automation|Dashboard in Excel| Provide Excel consulting through macro (VBA) automation |Financial Modeling | Ethical Hacking

Wednesday, 15 June 2011

Find content of folder

Insert below code in standard module & run the macro, you will get File name with extension in Column A,
File size in column B, Date & Time modified in column C.

Sub Directory()
Dim r As Integer, F As String, Directory As String
Directory = "C:\Users\MAHESH\Desktop\Temp\"
r = 1
Cells(r, 1) = "FileName"
Cells(r, 2) = "Size"
Cells(r, 3) = "Date/Time"
Range("A1:c1").Font.Bold = True
'Get Directory
F = Dir(Directory)
Do While F <> ""
r = r + 1
Cells(r, 1) = F
Cells(r, 2) = FileLen(Directory & F)
Cells(r, 3) = FileDateTime(Directory & F)
'Get next File
F = Dir()
Loop
End Sub

No comments:

Post a Comment