[vba-excel] lister fichiers dossiers, et sous-dossiers


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

How to list recursively files, in an excel sheet ?


Copy this code and paste it in your HTML
  1. Sub TousLesDossiers(LeDossier$, IDX As Long)
  2. 'Frederic Sigonneau
  3. IDX = Range("A65536").End(xlUp).Rows.Row
  4. Dim fso As Object, Dossier As Object
  5. Dim sousRep As Object, Flder As Object
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. Set Dossier = fso.GetFolder(LeDossier)
  8.  
  9. 'Set Dossier = USF_Options_Excel!TB_DD
  10. 'MsgBox Dossier
  11. 'MsgBox LeDossier
  12. 'IDX = IDX + 1
  13. 'examen du dossier courant
  14. 'Cells(IDX, 1).Value = LeDossier
  15. 'Stop
  16. For Each Flder In Dossier.subfolders
  17. IDX = IDX + 1
  18. Cells(IDX, 1).Value = Flder.Path
  19. ActiveSheet.Hyperlinks.Add Anchor:=Cells(IDX, 2), Address:= _
  20. Flder.Path
  21. Next
  22. 'Stop
  23. 'traitement récursif des sous dossiers
  24. For Each sousRep In Dossier.subfolders
  25. TousLesDossiers sousRep.Path, IDX
  26. Next sousRep
  27. Set fso = Nothing
  28. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.