Public chemin As String
Public ceclasseur As String
Public nomtxt As String
Public ii As Single
Public derligne As Single
Sub ImportTextFile()
choisirRepertoire
ceclasseur = ThisWorkbook.Name
[COLOR="Yellow"]Set fc = CreateObject("Scripting.FileSystemObject").GetFolder(chemin).Files[/COLOR]
If fc.Count > 0 Then 'il y a des fichiers
ii = 0
For Each f1 In fc
If Right(f1.Name, 3) = "txt" Or Right(f1.Name, 3) = "txt" Then 'c'est un fichier texte
nomtxt = f1.Name
ii = ActiveSheet.Range("a65536").End(xlUp).Row
Workbooks.OpenText FileName:= _
chemin & "\" & f1.Name, Origin:=xlMSDOS, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Semicolon:=False, Other:=True, OtherChar:="|"
'inclu_nom_fichier début
derligne = ActiveSheet.Range("a65536").End(xlUp).Row
Range("A1:A" & derligne).Select
Selection.Insert Shift:=xlToRight
Selection.FormulaR1C1 = f1.Name
'inclu_nom_fichier fin
derligne = ActiveSheet.Range("a65536").End(xlUp).Row
Rows(1 & ":" & derligne).Copy Workbooks(ceclasseur).ActiveSheet.Range("A" & ii + 2)
ActiveWorkbook.Close savechanges:=False
End If
Next
End If
Range("A1").Select
Rows.HorizontalAlignment = -4108 'centrer le texte
Columns("c").NumberFormat = "0" 'colone b format nombre
Columns("p").NumberFormat = "0" 'colone o format nombre
End Sub
Sub choisirRepertoire()
Application.Dialogs(xlDialogOpen).Show
End Sub
Sub clear()
Dim i%
For i = 500 To 7 Step -1 'à adapter à la situation
If Application.CountA(Rows(i)) Then Rows(i).Delete
Next
End Sub