Bonjour,
Je souhaite réaliser une jointure sur le champ ID entre 2 fichiers xls distincts, en utilisant en vba une connexion Microsoft.ACE.OLEDB.
Je n'arrive pas à écrire la requête en intégrant l'adresse des fichiers c:\1.xls c:\2.xls dans :
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 Dim strConnection As String Dim strQuery As String Dim objConnection As Object Dim objRecordSet As Object strConnection = _ "Provider=Microsoft.ACE.OLEDB.12.0;" & _ "User ID=Admin;" & _ "Data Source='" & ThisWorkbook.FullName & "';" & _ "Mode=Read;" & _ "Extended Properties=""Excel 12.0 Macro;"";" Fichier1 = "c:\1.xls" Fichier2 = "c:\2.xls" strQuery = "SELECT [Fichier1].[Utilisateur$].[id], [Fichier1].[Utilisateur$].[Nom], [Fichier2].[commande$].[Quantité]" & _ "FROM [Utilisateur$] INNER JOIN [commande$] ON [Utilisateur$].[id] = [commande$].[id] " Set objConnection = CreateObject("ADODB.Connection") objConnection.Open strConnection Set objRecordSet = objConnection.Execute(strQuery) Dim i As Long With objSheet Sheets("Test").Cells.Delete For i = 1 To objRecordSet.Fields.Count Sheets("Test").Cells(1, i).Value = objRecordSet.Fields(i - 1).Name Next Sheets("Test").Cells(2, 1).CopyFromRecordset objRecordSet Sheets("Test").Cells.Columns.AutoFit End With objConnection.Close
Pouvez-vous m'aider. Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part strQuery = "SELECT [Fichier1].[Utilisateur$].[id], [Fichier1].[Utilisateur$].[Nom], [Fichier2].[commande$].[Quantité] FROM [Utilisateur$] INNER JOIN [commande$] ON [Utilisateur$].[id] = [commande$].[id] "
Cdlt
Partager