Convertir un fichier text avec pipe en excel

Bonjour,
mon problème est le suivant, je possède un fichier text avec des pipes | comme séparateurs et je voudrais le convertir dans excel en remplacent les | par des colonnes distinctes, comment faire ?

Dans l'autre sens, en partant d'un fichier excel avec des colonne, je l'enregistre en fichier text et je remplace ^t par | et ca roule tout seul...
Je voudrais faire l'inverse, comment faire ??

merci

3 réponses

  1. Contributeur
    salut
    menu Données / données externes / importer le fichier txt
    et choisir | comme séparateur
    0
    1. Bonjour
      Voila une macro pour convertir les pipes

      Private Sub ChoixCumulTxt()
      Dim dossier As FileDialog
      ChoixChemin = ActiveWorkbook.Path & Application.PathSeparator
         Set dossier = Application.FileDialog(msoFileDialogFilePicker)
            With dossier
               .AllowMultiSelect = False
               .InitialFileName = ChoixChemin
               .Title = "Choix d'un fichier TXT"
               .Filters.Clear
               .Filters.Add "Fichier txt ", "*.txt", 1
                  If .Show = -1 Then
                     Chemin = .SelectedItems(1)
                     LireTxtCumul Chemin
                  End If
            End With
         Set dossier = Nothing
      End Sub
      
      Sub LireTxtCumul(NomFichier)
      Dim Ar() As String
      Dim Sep As String
         With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .Calculation = xlManual
         End With
      'Feuil1.Select
      Sep = "|"
      'Lig = Range("A" & Rows.Count).End(xlUp).Row + 1
      Lig = 1
      ' -----------------------------------------
          Open NomFichier For Input As #1
              Do While Not EOF(1)
                  Line Input #1, Chaine
                     Ar = Split(Chaine, Sep)
                     Col = 1
                        For X = LBound(Ar) To UBound(Ar)
                           Cells(Lig, Col) = Ar(X)
                           Col = Col + 1
                        Next
                  Lig = Lig + 1
              Loop
          Close #1
      ' -----------------------------------------
         With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .CutCopyMode = False
            .Goto [A1], True
         End With
      End Sub
      

      A+
      Maurice
      0
      1. bonjour

        appuyer sur Alt Gr 6 à la fois
        -1