Importation de plusieurs fichiers texte avec VBA
tinyspot0103
-
eriiic Messages postés 25847 Date d'inscription Statut Contributeur Dernière intervention -
eriiic Messages postés 25847 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
On voudrait importer tous les fichiers texte dans un dossier, voici le code:
Option Explicit
Public l As Long
Sub Import_Data()
Dim Fichier As String, Chemin As String
Dim i As Long
'Répertoire contenant les fichiers
Chemin = "\\rohan\T\20802223\Bureau\VBA M2\Projet VBA"
Fichier = Dir(Chemin & "\*.txt")
'Boucle sur les fichiers
Do While Fichier <> ""
i = Range("A65536").End(xlUp).Row + 1
ImportText Chemin & "\" & Fichier, Cells(i, 1)
Fichier = Dir
Loop
'Supprimer l'entête des fiches apart de celle de fiche 1
For l = Cells(1, 1).CurrentRegion.Rows.Count To 3 Step -1
If Cells(l, 1).Value = "day" Then
Cells(l, 1).EntireRow.Delete
End If
Next l
Cells(1, 1).EntireRow.Delete
End Sub
Le problème est qu'il marche 1 fois sur 1000, il envoie 1 message comme "sub function non définie"
Merci à tous!!!!!!!!!!
On voudrait importer tous les fichiers texte dans un dossier, voici le code:
Option Explicit
Public l As Long
Sub Import_Data()
Dim Fichier As String, Chemin As String
Dim i As Long
'Répertoire contenant les fichiers
Chemin = "\\rohan\T\20802223\Bureau\VBA M2\Projet VBA"
Fichier = Dir(Chemin & "\*.txt")
'Boucle sur les fichiers
Do While Fichier <> ""
i = Range("A65536").End(xlUp).Row + 1
ImportText Chemin & "\" & Fichier, Cells(i, 1)
Fichier = Dir
Loop
'Supprimer l'entête des fiches apart de celle de fiche 1
For l = Cells(1, 1).CurrentRegion.Rows.Count To 3 Step -1
If Cells(l, 1).Value = "day" Then
Cells(l, 1).EntireRow.Delete
End If
Next l
Cells(1, 1).EntireRow.Delete
End Sub
Le problème est qu'il marche 1 fois sur 1000, il envoie 1 message comme "sub function non définie"
Merci à tous!!!!!!!!!!
A voir également:
- Importation de plusieurs fichiers texte avec VBA
- Renommer plusieurs fichiers en même temps - Guide
- Explorateur de fichiers - Guide
- Fichiers epub - Guide
- Transcription audio en texte word gratuit - Guide
- Excel cellule couleur si condition texte - Guide