Bonjour,

en m'inspirant du très bon boisgontierjacques, j'ai adapté son code pour mon usage.
Source : http://boisgontierjacques.free.fr/pa...ado.htm#Import
J'arrive très bien à copier des données depuis un fichier fermé.
Or, je souhaite copier des données depuis plusieurs fichiers fermés (tous identique de par leur structure, mais différent de part leur contenu).
Ma boucle ne copie que les données du premier fichier, alors que la variable "odmfile" change bien à chaque boucle ...

Où est mon erreur ?

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
 
Sub abracadabra()   'tool to consolidate data from several closed files
' Microsoft ActiveX DataObject must be activated
    Dim counter As Integer
    Dim odmfile As String         'string containing the path and the name of a file : c:\toto\file.xlsx
    Dim t_odmFileList As ListObject	'Table containing a list with the path and the name of each files : c:\toto\file1.xlsx
    Dim Source As ADODB.Connection
    Dim Requete As ADODB.Recordset
 
    Set t_odmFileList = Range("t_odmFileList").ListObject
 
    Application.ScreenUpdating = False
 
    For counter = 1 To t_odmFileList.DataBodyRange.Rows.Count
        odmfile = t_odmFileList.DataBodyRange(counter, 2).Value
        Set Source = New ADODB.Connection
        Source.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & odmfile & ";Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'"
        Set Requete = Source.Execute("[Feuil1$A1:L100]")
        [K1].CopyFromRecordset Requete        'copy data in temporary table
        Requete.Close
        Source.Close
        Set Requete = Nothing
        Set Source = Nothing
    Next counter
 
    Application.ScreenUpdating = True
End Sub