IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Comment Microsoft.Jet.OLEDB.4.0 peut fonctionner? [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aube (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 184
    Points : 83
    Points
    83
    Par défaut Comment Microsoft.Jet.OLEDB.4.0 peut fonctionner?
    Bonjour :

    Voici une partie de mon code pour copier une plage d'un classeur fermé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Private Sub ConnectCLasseur(ConnectCL As Object, _
                                Fichier As String, _
                                Optional Rs)
     
        Set ConnectCL = CreateObject("ADODB.Connection")
     
        If Not IsMissing(Rs) Then Set Rs = CreateObject("ADODB.Recordset")
     
        ConnectCL.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _    '<----------------------
                       "Data Source=" & Fichier & ";" & _                    '<----------------------   Erreur
                       "Extended Properties=""Excel 8.0;HDR=NO;IMEX=2;"""  '<-------------
     
    End Sub
    Il y a toujours une erreur d'exécution : "La table externe n'est pas dans le format attendu". J'ai déjà coché la librairie
    "Microsoft Jet and Replication Objects 2.6".

    Qu'est-ce qu'il y a comme faute? Merci d'avance.

  2. #2
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 274
    Points
    11 274

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Test comme ça
    Connexion.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & chemin & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2;"""

  4. #4
    Expert éminent
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    3 453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 3 453
    Points : 6 871
    Points
    6 871
    Par défaut
    Bonjour,

    Tu cherche à te connecter à un fichier .csv donc ça, ça ne marche pas : "Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2"
    Plutôt ceci : "Extended Properties=""text;HDR=YES;FMT=Delimited;"
    Regarde l'autre post et fais un test

  5. #5
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aube (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 184
    Points : 83
    Points
    83
    Par défaut
    Citation Envoyé par rdurupt Voir le message
    Bonjour,

    Test comme ça
    Connexion.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & chemin & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2;"""
    Bonjour :

    Cela ne fonctionne toujours pas. J'aurais dû préciser que c'est un fichier .csv.

  6. #6
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aube (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 184
    Points : 83
    Points
    83
    Par défaut
    Citation Envoyé par Theze Voir le message
    Bonjour,

    Tu cherche à te connecter à un fichier .csv donc ça, ça ne marche pas : "Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2"
    Plutôt ceci : "Extended Properties=""text;HDR=YES;FMT=Delimited;"
    Regarde l'autre post et fais un test
    Bonjour :
    Vous avez raison. C'est un fichier .csv. Puis j'ai essayé après la modification :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Private Sub ConnectCLasseur(ConnectCL As Object, _
                                Fichier As String, _
                                Optional Rs)
     
        Set ConnectCL = CreateObject("ADODB.Connection")
     
        If Not IsMissing(Rs) Then Set Rs = CreateObject("ADODB.Recordset")
     
        ConnectCL.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                       "Data Source=" & Fichier & ";" & _
                       "Extended Properties=""text;HDR=YES;FMT=Delimited;"""
    Il me renvoie :Nom : Capture.JPG
Affichages : 1582
Taille : 24,3 Ko

    Sauf que C:\Users\stg_pao\Desktop\ExportStat_Global_Synthese.csv est exactement l'emplacement du fichier.

  7. #7
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    ta connexion laissait entendre que c'était de l'Excel et pas du csv!
    http://www.developpez.net/forums/d15...s/#post8430556
    http://www.developpez.net/forums/d15...s/#post8431023

    la connexion se fait sur un répertoire (Serveur) pas un fichier: C:\Users\stg_pao\Desktop\ExportStat_Global_Synthese.csv

  8. #8
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aube (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 184
    Points : 83
    Points
    83
    Par défaut
    Merci pour ton rappel.
    Maintenant j'ai réussi de connecter. Par contre il reste un problème de compatibilité. http://www.developpez.net/forums/d15...f/#post8435573

  9. #9
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
     
    #If VBA7 Then
    Declare PtrSafe  Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare  PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare PtrSafe  Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Declare PtrSafe  Function CloseClipboard Lib "User32" () As Long
    Declare PtrSafe  Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
    Declare PtrSafe  Function EmptyClipboard Lib "User32" () As Long
    Declare  PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    Declare  PtrSafe Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    #Else
     Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Declare Function CloseClipboard Lib "User32" () As Long
    Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
    Declare Function EmptyClipboard Lib "User32" () As Long
    Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    #End If
    Public Const GHND = &H42
    Public Const CF_TEXT = 1
    Public Const MAXSIZE = 4096
     Sub test()
    Dim Cn As Object, txt As String
    Set Cn = CreateObject("Adodb.Connection")
     Cn.Open "Provider =Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyTest\;Extended Properties=""Text;HDR=YES;FMT=Delimited(;);"";"
     Set rs = CreateObject("ADODB.RecordSet")
     rs.Open "select * from [cdfast_clipro8.csv]", Cn
    txt = rs.GetString
    txt = Replace("" & txt, ";", vbTab)
    ClipBoard_SetData "" & txt
    ActiveCell.PasteSpecial xlPasteAll
    End Sub
     
    Function ClipBoard_SetData(MyString As String)
       Dim hGlobalMemory As Long, lpGlobalMemory As Long
       Dim hClipMemory As Long, X As Long
     
       ' Allocate moveable global memory.
       '-------------------------------------------
       hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
     
       ' Lock the block to get a far pointer
       ' to this memory.
       lpGlobalMemory = GlobalLock(hGlobalMemory)
     
       ' Copy the string to this global memory.
       lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
     
       ' Unlock the memory.
       If GlobalUnlock(hGlobalMemory) <> 0 Then
          MsgBox "Could not unlock memory location. Copy aborted."
          GoTo OutOfHere2
       End If
     
       ' Open the Clipboard to copy data to.
       If OpenClipboard(0&) = 0 Then
          MsgBox "Could not open the Clipboard. Copy aborted."
          Exit Function
       End If
     
       ' Clear the Clipboard.
       X = EmptyClipboard()
     
       ' Copy the data to the Clipboard.
       hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
     
    OutOfHere2:
     
       If CloseClipboard() = 0 Then
          MsgBox "Could not close Clipboard."
       End If
     
       End Function

  10. #10
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aube (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 184
    Points : 83
    Points
    83
    Par défaut
    Merci. Je te répondrai dans l'autre post.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. microsoft jet oledb
    Par philguio dans le forum Windows Forms
    Réponses: 2
    Dernier message: 01/01/2010, 21h49
  2. Microsoft Jet OLEDB 4.0 Windows 7
    Par leeloo95 dans le forum Framework .NET
    Réponses: 3
    Dernier message: 16/12/2009, 14h36
  3. Microsoft Jet oledb 4.0 sur Windows 7
    Par leeloo95 dans le forum Windows 7
    Réponses: 0
    Dernier message: 17/11/2009, 09h33
  4. Réponses: 6
    Dernier message: 02/05/2009, 16h40
  5. Microsoft.Jet.OLEDB & Pilote ISAM
    Par Ryansoldier dans le forum Débuter
    Réponses: 0
    Dernier message: 28/04/2009, 13h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo