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
| Function NbFeuillesClasseurFermé(chemin)
Dim Conn, Cat, Tbl
Dim Connex$
Connex = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & chemin & ";" & _
"Extended Properties=Excel 8.0;"
Set Conn = CreateObject("ADODB.Connection")
Conn.Open Connex
Set Cat = CreateObject("ADOX.Catalog")
Set Cat.ActiveConnection = Conn
For Each Tbl In Cat.Tables
If InStr(1, Tbl.Name, "$") > 0 Then Nb = Nb + 1
Next
NbFeuillesClasseurFermé = Nb
Conn.Close
Set Cat = Nothing
Set Conn = Nothing
End Function
Sub parcours()
Application.DisplayAlerts = False
Dim fs, f, f1, fc, u
Dim tablo() As Variant
Dim tablo2() As Variant
u = 1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\Boeuf\david excel\Excel")
Set fc = f.Files
For Each f1 In fc
If UCase(Right(f1.Name, 4)) = ".XLS" Then
ReDim Preserve tablo(1 To u)
tablo(u) = f1.Name
u = u + 1
Else
End If
Next
u = 1
For t = 1 To UBound(tablo, 1)
ReDim Preserve tablo2(1 To t)
tablo2(t) = f & "\" & tablo(t) ' & Cells(5, 6).Value
Next
Erase tablo
u = 1
For t = 1 To UBound(tablo2, 1)
chemin = tablo2(t)
For sh = 1 To NbFeuillesClasseurFermé(chemin)
ReDim Preserve tablo(1 To u)
tablo(u) = tablo2(t) & "sheets(" & sh & ")"
u = u + 1
Next
Next |