[vba-excel] lister tous les fichiers répertoires et sous-répertoires


/ Published in: Visual Basic
Save to your folder(s)

How to list files in directories and subdirectories ?


Copy this code and paste it in your HTML
  1. Option Explicit
  2. Sub ListeFichiersRepert()
  3. Dim Fso As Object
  4. Dim MonRepertoire As String, f As Object, x As Integer
  5. Dim f1 As Object, f2 As Object
  6. Set Fso = CreateObject("Scripting.FileSystemObject")
  7. MonRepertoire = "C:\Users\Moi\Documents\Dossier Excel"
  8. x = 1
  9. For Each f In Fso.GetFolder(MonRepertoire).Files
  10. Cells(x, 1).Value = f.Name
  11. x = x + 1
  12. Next f
  13. x = 1
  14. For Each f1 In Fso.GetFolder(MonRepertoire).SubFolders
  15. Cells(x, 2).Value = f1.Name
  16. x = x + 1
  17. For Each f2 In f1.Files
  18. Cells(x - 1, 3).Value = f2.Name
  19. x = x + 1
  20. Next f2
  21. x = x - 1
  22. Next f1
  23. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.