Solved

Excel Macro - List Files and Subfolders with details

Posted on 2010-09-24
3
962 Views
Last Modified: 2012-05-10
Hi guys,

I need make a Macro to list in Excel all content of a folder (files, subfolders etc) with details example size and datetime.

Thanks!
0
Comment
Question by:Gonzalo Becerra
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 33753620
Try this - just modify the path and output range in the first sub as required:



Sub TestListFoldersAndFiles()

   FolderListing "C:\test", Range("A1")

End Sub

Sub FolderListing(strFilepath As String, ByRef rngOutput As Range)

   Dim fso As Object, fdrSelected, fdrSub, filTemp

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set fdrSelected = fso.GetFolder(strFilepath)

   With rngOutput

      .Value = fdrSelected.Path & " (" & fdrSelected.Files.Count & ")"

      .Font.Bold = True

   End With

   For Each filTemp In fdrSelected.Files

      Set rngOutput = rngOutput.Offset(1)

      rngOutput.Value = filTemp.Name

      rngOutput.Offset(, 1).Value = filTemp.Size

      rngOutput.Offset(, 2).Value = filTemp.DateLastModified

   Next filTemp

   Set rngOutput = rngOutput.Offset(2)

   For Each fdrSub In fdrSelected.SubFolders

      FolderListing fdrSub.Path, rngOutput

   Next fdrSub

   Set fso = Nothing



End Sub

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33754024
gbecerra,Glad to see you got an answer!You might also want to have a look at this PAQ:http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_25063189.html#a26340696In that comment, I have code that will enumerate the files in a directory, but allow you at runtime to browse to find the directory you want enumerated, and also allow you to indicate whether or not to traverse the subfolders and descendants.Patrick
0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 33754598
Thanks alot!! i check the two solutions and help me alot!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now