Sub test()
Dim Cn As Object, Tables() As String, Table, DerL As Long
Const MyRep = "C:\Myrep", AvecTitre = True
Set Cn = CreateObject("Adodb.Connection")
With Cn
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MyRep & ";Extended Properties=""Text;HDR=" & Array("No", "YES")(Abs(AvecTitre)) & ";FMT=Delimited;"""
Tables() = ListeTables(Cn)
For Each Table In Tables
ShemaIn MyRep, Replace(CStr(Table), "#", "."), "Delimited(;)"
DerL = Sheets("Feuil1").UsedRange.Rows.Count
If DerL = 1 Then DerL = 0
Sheets("Feuil1").Cells(DerL + 1, "A").Select
Sheets("Feuil1").Cells(DerL + 1, "A").CopyFromRecordset .Execute("select * from [" & Table & "]")
Next
.Close
End With
Set Cn = Nothing
End Sub
Property Get ListeTables(Connexion As Object) As String()
Dim t() As String, i As Integer
TableToutes = False
With Connexion.OpenSchema(20)
While Not .EOF
ReDim Preserve t(i)
t(i) = !TABLE_NAME
i = i + 1
.MoveNext
Wend
.Close
ListeTables = t
End With
End Property
Public Sub ShemaIn(Server As String, fichier As String, Delimited As String)
Dim txt As String
txt = "[" & fichier & "]" & vbCrLf & "Format= " & Delimited
Dim fso, NewFichier
Set fso = CreateObject("Scripting.FileSystemObject")
Set NewFichier = fso.OpenTextFile(Server & "\schema.ini", 2, True)
NewFichier.Write txt
NewFichier.Close
Set NewFichier = Nothing
Set fso = Nothing
End Sub