Solved

Create list in excel of all folders within a directory

Posted on 2011-02-17
5
418 Views
Last Modified: 2012-05-11
I am a bit confused on how to come up with a macro that lists the folders in a directory

Directory: Q:\Deburr issue\WT Review\Ship 0008

There are also some .zip files in this directory, but i just want to list the folders.

Thanks,

Brandon
0
Comment
Question by:KnutsonBM
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34915445
Try this:
Sub PlainFolderListing()
   Dim fso As FileSystemObject, fdrSelected, fdrSub, filTemp
   Dim strFilePath As String, rngOutput As Range
   
   ' change folder as required
   strFilePath = "Q:\Deburr issue\WT Review\Ship 0008"
   
   ' change list destination as required
   Set rngOutput = ActiveSheet.Range("A1")
   
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fdrSelected = fso.GetFolder(strFilePath)
   For Each fdrSub In fdrSelected.SubFolders
      rngOutput.value = fdrSub.Path
      Set rngOutput = rngOutput.Offset(1)
   Next fdrSub
   Set fso = Nothing

End Sub

Open in new window

0
 
LVL 6

Author Comment

by:KnutsonBM
ID: 34915462
at Dim fso As FileSystemObject i get 'Compile Error: User-defined type not defined'


any thoughts

Brandon
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 34915465
Change that to:
Dim fso As Object

Open in new window

0
 
LVL 6

Author Comment

by:KnutsonBM
ID: 34915482
what do i need to do to remove the path and leave just the name of the folder on the output?
0
 
LVL 6

Author Comment

by:KnutsonBM
ID: 34915491
nevermind i got it, changed fdrSub.Path to fdrSub.Name
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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

863 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

25 Experts available now in Live!

Get 1:1 Help Now