Return to Snippet

Revision: 76794
at July 29, 2019 06:45 by martinbrait


Initial Code
Sub ListAllFile() 
     
        Dim objFSO As Object 
        Dim objFolder As Object 
        Dim objFile As Object 
        Dim ws As Worksheet 
     
        Set objFSO = CreateObject("Scripting.FileSystemObject") 
        Set ws = Worksheets.Add 
     
         'Get the folder object associated with the directory
        Set objFolder = objFSO.GetFolder("C:\") 
        ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & "are:" 
     
         'Loop through the Files collection
        For Each objFile In objFolder.Files 
            ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name 
        Next 
     
         'Clean up!
        Set objFolder = Nothing 
        Set objFile = Nothing 
        Set objFSO = Nothing 
     
    End Sub

Initial URL

                                

Initial Description
Comment lister tous les fichiers d'un répertoire dans un fichier excel ?

Excel (VBA) list all filenames in a directory

mastipro

Initial Title
[VBA-EXCEL] Lister les fichiers d\'un répertoire donné

Initial Tags
files, directory

Initial Language
Visual Basic