1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Sub ExtraireFichiersTexte()
'Boucle sur les fichiers texte du dossier
' dans lequel se trouve le fichier Excel
Dim NomFichierTexte As String
Dim NomFichierFinal As String
Application.ScreenUpdating = False '
NomFichierTexte = Dir(ThisWorkbook.Path & "\*.txt")
Do While NomFichierTexte <> ""
ExtraireDonnees NomFichierTexte
NomFichierTexte = Dir()
Loop
NomFichierFinal = StrReverse(Left(StrReverse(ThisWorkbook.Path), _
InStr(1, StrReverse(ThisWorkbook.Path), "\") - 1))
ThisWorkbook.SaveAs NomFichierFinal
Application.ScreenUpdating = True
End Sub
Sub ExtraireDonnees(ByVal NomFichier As String)
' Extrait les données du fichier
Dim Classeur As Workbook
Dim Plage As Range
Dim Feuille As Worksheet
Dim CelluleCible As Range
Set Classeur = Workbooks.Open(NomFichier)
Set Feuille = Classeur.Worksheets(1)
Set CelluleCible = ThisWorkbook.Worksheets("Consolidation").Range("a" & ThisWorkbook.Worksheets("Consolidation").Rows.Count).End(xlUp)(2)
Set Plage = Feuille.UsedRange
Feuille.UsedRange.TextToColumns Destination:=Range("a1"), _
DataType:=xlDelimited, other:=True, otherchar:=";"
Set Plage = Range(Feuille.Range("a2"), Feuille.Cells.SpecialCells(xlCellTypeLastCell))
Plage.Copy Destination:=CelluleCible
Classeur.Close savechanges:=False
End Sub |
Partager