Sub ImportTextFile()
'code de Coriolan modif par MJ issu de http://www.excel-downloads.com/forum/83569-pb-dimportation-dobjets-dans-une-macro.html
'Dim ceclasseur As String
'Dim monrépertoire As String
Dim ii As Integer, nomtxt As String, Ligne As String, TabLigne, i As Long
Dim fc, f1, fso
'monrépertoire = "nom du répertoire contenant les fichiers .txt à importer"
'Stop
chemin = "J:\npai\Invalides\test"
ceclasseur = ThisWorkbook.Name
Set fso = CreateObject("Scripting.FileSystemObject")
Set fc = fso.GetFolder(chemin).Files
If fc.Count > 0 Then 'il y a des fichiers
ii = 0
For Each f1 In fc
If UCase(f1.Name) Like "*.TXT" Then 'c'est un fichier texte
'ii = ii + 1
nomtxt = f1.Name
ii = ActiveSheet.Range("a65536").End(xlUp).Row + 1
Set f1 = fso.OpenTextFile(chemin & "\" & nomtxt, 1, False, -2)
Do Until f1.AtEndOfStream
Ligne = f1.readline
If Ligne Like "*@*.*" Then
TabLigne = Split(Ligne, ";")
For i = LBound(TabLigne) To UBound(TabLigne)
ActiveSheet.Cells(ii, i + 1).Value = TabLigne(i)
Next i
ii=ii+1
End If
Loop
f1.Close
End If
Next
End If
Set f1 = Nothing
Set fc = Nothing
Set fso = Nothing
End Sub