|
Sub a()
Dim mypath$, myfile$, arr, i%
Dim cnn As Object
Dim Sql As String
Set cnn = CreateObject("ADODB.CONNECTION")
arr = Sheet2.[d2].CurrentRegion
mypath = ThisWorkbook.Path & "\"
For i = 2 To UBound(arr)
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=NO'; Data Source=" & mypath & arr(i, 1)
Sql = "select * from [" & arr(i, 2) & "$" & arr(i, 3) & "]"
With Sheets(arr(i, 4))
.Range(arr(i, 5)) = ""
.[c3].CopyFromRecordset cnn.Execute(Sql)
End With
cnn.Close
Next
Set cnn = Nothing
End Sub |
|