Import fichier csv

Bonjour,

J'ai une macro qui me permet d'importer un fichier CSV dans un fichier xlsm dans la feuille "import csv"

Sub import_csv()
Dim Ctr As Integer, Desti As Range

Fichier = Application.GetOpenFilename("CSV Files (*.CSV), *.csv")

With Sheets("import csv")
Set Desti = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
With .QueryTables.Add(Connection:= _
"TEXT;" & Fichier, _
Destination:=Desti)
Ctr = Ctr + 1
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 1, 1)
.TextFileFixedColumnWidths = Array(19, 30, 5)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End With
End Sub


Les données du fichier csv sont bien collées dans la bonne feuille mais pas dans le bon format

Je ne sais pas comment paramétrer dans ma macro le paramétrage ci-dessous :




3 réponses

  1. Bonjour,

    Il ta des ";" en trop dans la ligne de donnees , ce qui provoque des decalage de colonnes......
    Votre csv est extrait de quel endroit ????
    0
    1. Bonjour,
      Merci pour votre réponse j'ai corrigé les paramètres à changer et ça marche tip top
      Voici le nouveau code :

      Sub import_csv()
      Dim Ctr As Integer, Desti As Range

      Fichier = Application.GetOpenFilename("CSV Files (*.CSV), *.csv")

      With Sheets("import csv")
      Set Desti = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
      With .QueryTables.Add(Connection:= _
      "TEXT;" & Fichier, _
      Destination:=Desti)
      Ctr = Ctr + 1
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = True
      .RefreshOnFileOpen = False
      .RefreshStyle = xlInsertDeleteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = True
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 65001
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = False
      .TextFileTabDelimiter = True
      .TextFileSemicolonDelimiter = True
      .TextFileCommaDelimiter = False
      .TextFileSpaceDelimiter = False
      .TextFileColumnDataTypes = Array(2, 1, 1, 1)
      .TextFileFixedColumnWidths = Array(19, 30, 5)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
      End With
      End With
      End Sub


      Par contre le fichier csv après l'import dans mon fichier xlsm vient se positionner en cellule A2 alors que je voudrai qu'il se positionne en A1

      Que dois-je modifier ?
      Merci pour votre aide
      0
      1. Re,

        Remplacez Desti par A1 si ca ne change pas
        0
    2. Merci c'est tout bon :-)
      Très bonne soirée !
      0