Lister noms et contenu fichier .txt dans fichier Excel

salut forum !

j'ai besoin de votre aide. je suis a la recherche d'une macro qui permet de lister les noms et le contenu des fichiers .txt dans un fcihier excel.

merci de votre aide.

voici j'ai trouvé cette macro qui me permet de lister les noms des fichiers et la 2eme ligne de chaque fichier texte.

comment faire pour importer tout les contenus des fichiers.

Merci beaucoup!

Sub ImportTextFiles()

   'Declare the variables
   Dim strFolder As String
   Dim strFile As String
   Dim strData As String
   Dim r As Long
   Dim c As Long

   'Turn off screen updating
   Application.ScreenUpdating = False

   'Define the path to the folder containing the text files
   strFolder = "C:\Users\LG\Desktop\gg\lot"

   'Ensure that the path ends with a backslash
   If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

   'Call the first text file from folder
   strFile = Dir(strFolder & "*.txt")

   'Loop through each text file within the folder
   Do While Len(strFile) > 0
       r = r + 1
       'Open the current text file
       Open strFolder & strFile For Input As #1
           'Import the data from the current text file
           Do Until EOF(1)
               c = c + 1
               'Limit the importing to the first 21 columns of the workbook (can be deleted if each text file contains no more than 21 rows of data)
               If c > 2 Then Exit Do
               Input #1, strData
               Cells(r, c).Value = strData
               Cells(r, 1) = strFile
               Cells(r, 1).Replace What:=".txt", Replacement:=""
           Loop
       Close #1
       c = 0
       'Call the next text file
       strFile = Dir
   Loop

   'Turn back on screen updating
   Application.ScreenUpdating = True

   MsgBox "Completed...", vbInformation

End Sub
Rechercher des sujets similaires à "lister noms contenu fichier txt"