Last active
December 16, 2015 11:28
-
-
Save sharkoz/5427052 to your computer and use it in GitHub Desktop.
[Excel] Merge csv or xls files in a single xls file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub recup() | |
Range("A1").Select 'sélectionner la cellule de début | |
Chemin = "C:\Documents and Settings\ccharlier-adc\Mes documents\Téléchargements\" 'saisir le chemin complet du dossier où se trouvent les fichiers | |
Fichier = Dir(Chemin & "EC_*.csv") ' Premier fichier | |
Do While Fichier <> "" | |
'Pour des xls | |
'Workbooks.Open Filename:=Chemin & Fichier | |
'Pour des csv | |
Workbooks.OpenText Filename:=Chemin & Fichier, DataType:=xlDelimited, Semicolon:=True, Local:=True | |
Range("A:Z").Copy | |
ThisWorkbook.Activate | |
Feuille = Left(Replace(Replace(Right(Left(Fichier, Len(Fichier) - 4), Len(Fichier) - 7), "_", " "), ".", " "), 30) | |
Sheets.Add.Name = Feuille | |
Sheets(Feuille).Activate | |
ActiveSheet.Paste | |
Windows(Fichier).Activate | |
Application.CutCopyMode = False | |
ActiveWorkbook.Close savechanges:=False | |
ThisWorkbook.Activate | |
Range("A65536").End(xlUp).Offset(1, 0).Select | |
Fichier = Dir ' Fichier suivant | |
Loop | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment