PDA

View Full Version : How to make a list of Files and folders of a directory in excel



Garrak
12-09-2013, 10:45 AM
Hi,

So I have this code that enable me to get all files in a folder, but, as I try to change it to add the folder in that same folder(not the files in the folder), it won't work.

Here's the code:

Private Sub blister_Click()


Dim fso As New Scripting.FileSystemObject
Dim fichier As File
Dim dossier As Folder
Dim cNoLigne As Currency


Sheets("Inventaire Macro").Cells.Clear


ActiveWorkbook.Sheets("Inventaire Macro").Range("A2").Value = "Nom des films"


Set dossier = fso.GetFolder(Range("J3")) ' J3 is where the directory adress is



For Each fichier In dossier.Files
Range("Liste").Offset(cNoLigne, 0).Value = fichier.Name

cNoLigne = cNoLigne + 1

Next

'This one works perfectly, but I can't figure out how to modify it to get the folder. My first idea was to add a second block that would select the folder instead of the file and add the name to the same list of the list of files. Any idea?


For Each fichier In dossier.Files
Range("Liste").Offset(cNoLigne, 0).Value = fichier.Name


cNoLigne = cNoLigne + 1


Next _____________________________________________________

Thanks

GTO
12-09-2013, 06:33 PM
Hi,

So I have this code that enable me to get all files in a folder, but, as I try to change it to add the folder in that same folder(not the files in the folder), it won't work.

'This one works perfectly, but I can't figure out how to modify it to get the folder. My first idea was to add a second block that would select the folder instead of the file and add the name to the same list of the list of files. Any idea?

Greetings Garrak and welcome to VBAX :-)

I am not quite sure what you are asking. Are you wishing to return a list of files and subfolders in a certain folder (without listing the files residing in any of the subfolders)?

Mark