XL 2019 Importer données blocs notes (txt) dans excel

Bastien43

XLDnaute Occasionnel
Bonjour,

Je dispose d'un fichier texte et je souhaite importer les données dans excel. Cependant, je n'arrive pas à avoir une valeur par cellule. Comment faire svp ? En indiquant séparateur (espace ou tabulation), cela ne fonctionne pas...

Je vous remercie,
Cordialement
Bastien
 

Pièces jointes

  • Données.txt
    51 KB · Affichages: 8

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour,
Un essai en PJ avec :
VB:
Sub ReadTxtFile()
    On Error GoTo Erreur
    Dim Chaine As String, Fichier As String, UneLigne As String, i As Integer, f As Integer, T(10000), Lig%, Col%
    Cells.ClearContents
    Classeur = ThisWorkbook.Name
    Fichier = ActiveWorkbook.Path & "\" & "Données.txt"
    f = FreeFile
    Open Fichier For Input As #f
    i = 0
    While Not EOF(f)
      i = i + 1
      Line Input #f, UneLigne
      T(i) = UneLigne
    Wend
    Close #f
    With Workbooks(Classeur).Sheets("Feuil1"): .Activate
        For Lig = 1 To UBound(T)
            tablo = Split(T(Lig), " ")
            Col = 1
            For i = 0 To UBound(tablo)
                If tablo(i) <> "" Then
                    If Left(tablo(i), 1) = "=" Then tablo(i) = "'" & tablo(i)
                    .Cells(Lig, Col) = tablo(i)
                    Col = Col + 1
                End If
            Next i
        Next Lig
    End With
    Exit Sub
Erreur:
    MsgBox "Le fichier de sortie est inaccessible"
End Sub
 

Pièces jointes

  • ReadTxtFile.xlsm
    38.6 KB · Affichages: 6

Discussions similaires

Réponses
0
Affichages
225

Statistiques des forums

Discussions
312 177
Messages
2 085 972
Membres
103 073
dernier inscrit
MSCHOE16