+ Reply to Thread
Results 1 to 2 of 2

Création d'un Pivottable à partir d'un Pivotcache et un fichier cvs

  1. #1
    Registered User
    Join Date
    07-17-2015
    Location
    Madagascar
    MS-Off Ver
    2013
    Posts
    1

    Exclamation Création d'un Pivottable à partir d'un Pivotcache et un fichier cvs

    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

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello jjerji,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2014, 09:36 AM
  2. [SOLVED] Perte de contact avec EXCEL à la fermeture d'un fichier
    By ARAGON31 in forum Non English Excel
    Replies: 5
    Last Post: 06-10-2014, 03:19 AM
  3. copier plusieurs fichier sous un fichier maitre
    By grunt in forum Non English Excel
    Replies: 3
    Last Post: 07-02-2013, 11:25 AM
  4. Replies: 0
    Last Post: 08-06-2012, 01:59 PM
  5. Pivottable Creation help
    By naveen.narayan in forum Excel General
    Replies: 6
    Last Post: 05-24-2010, 10:16 PM
  6. liaison autre fichier
    By [email protected] in forum Excel General
    Replies: 2
    Last Post: 06-02-2006, 05:40 AM
  7. Setting CommandText property of PivotCache fails if cache has >1 PivotTable
    By ashortxl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1