Bonjour,
J'ai une macro excel qui ouvre une boîte de dialogue afin de sélectionner un fichier .csv et le convertir ( voir code ci-dessous . Le problème est que le fichier me renvoie l'erreur suivante, ai-je mis la mauvaise source ?
Dim FD As Office.FileDialog
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
.InitialFileName = ThisWorkbook.Path & "\*.csv" 'adapter le répertoire
.Show
If .SelectedItems.Count > 0 Then fichier = .SelectedItems(1)
End With
ActiveWorkbook.Queries.Add Name:="Customer_hotline", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(File.Contents(" & fichier & "),[Delimiter="","", Columns=14, Encoding=65001, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""En-têtes promus"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & " #""Type modifié"" = Table.TransformColumnTypes(#""En-têtes promus"",{{""CostType"", type text}, " & _
"{""TicketID"", Int64.Type}, {""TicketType"", type text}, {""CompanyCode"", type text}, {""InterventionDay"", type date}, {""ServicePackage"", type text}, {""NoteCreatedByTeam"", type text}, {""NoteCreatedBy"", type text}, {""Title"", type text}, {""Amount"", type number}, {""Unit"", Currency.Type}, {""Total"", Int64.Type}, {""Billable"", type text}, {""Invoiced"", t" & _
"ype logical}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Type modifié"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Customer_hotline;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Customer_hotline]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Customer_hotline"
.Refresh BackgroundQuery:=False
Merci de votre aide !