Ce code marche bien avec Excel 2003 mais pas avec Excel 2010 et 2013! Le message d'erreur est le suivant :

"Erreur 1004 : [Microsoft][Pilote ODBC texte] Trop peu de paramètre. 7 attendu"

J'aimerais que quelqu'un m'aide à résoudre ce type d'erreur.


Private Sub CreatePivot(path As String, fileName As String, sheetName As String, PivotName As String)
'
'
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim ConString As String
Dim QueryString As String
Dim DataRange As Range
Dim i, nrow As Integer
Dim tabName As String

With Application
.Calculation = xlManual
.CalculateBeforeSave = False
End With

Application.EnableEvents = False
Application.ScreenUpdating = False

' Delete sheet if it exists
On Error Resume Next
Application.DisplayAlerts = False
Sheets(sheetName).Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal)

ConString = "ODBC;Driver={Microsoft Text Driver (*.txt; *.csv)};DriverId=27;FIL=text"

QueryString = "SELECT Sim.SimCode, Sim.rlab, Sim.clab, Sim.page, Sim.Variable, Sim.Value" _
& Chr(13) & "" & Chr(10) & "FROM `" & path & "`\" & fileName & " Sim"

With PTCache
.Connection = ConString
.CommandType = xlCmdSql
.CommandText = QueryString
End With

' Add new worksheet
Worksheets.Add
ActiveSheet.Name = sheetName

' Create Pivot Table

Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets(sheetName).Range("A1"), _
TableName:=PivotName)
End Sub