Sub Power_Query()
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
Dim T#
T = Timer
ActiveWorkbook.Queries.Add Name:="JournalReport", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Excel.Workbook(File.Contents(""C:\Users\ilies\Desktop\test\JournalAux.xlsx""), null, true)," & Chr(13) & "" & Chr(10) & " JournalReport_Sheet = Source{[Item=""JournalReport"",Kind=""Sheet""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Type modifié"" = Table.TransformColumnTypes(JournalReport_Sheet,{{""Column1"", type any}, {""Column2"", type any}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", type te" & _
"xt}, {""Column6"", type text}, {""Column7"", type text}, {""Column8"", type text}, {""Column9"", type any}, {""Column10"", type datetime}, {""Column11"", type any}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Type modifié"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""JournalReport"";Extended Properties=""""" _
, destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [JournalReport]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "JournalReport"
.Refresh BackgroundQuery:=False
End With
Dim cn As WorkbookConnection, qry As WorkbookQuery
On Error Resume Next
For Each cn In ActiveWorkbook.Connections
cn.Delete
Next cn
For Each qry In ActiveWorkbook.Queries
qry.Delete
Next qry
MsgBox "Durée " & Format(Timer - T, "0.00 \sec"), , "Import"
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub