|
ADO法速度快,请参考:
Sub ADO法()
Dim Fso As Object, File As Object, cnn As Object, rs As Object, SQL$, n&, arr, brr(), i&
Application.ScreenUpdating = False
arr = [{"AE13:AE13","CC20:CC20","DK20:DK20","CC22:CC22","N32:N32","DA32:DA32"}]
Set Fso = CreateObject("Scripting.FileSystemObject")
ReDim brr(1 To Fso.GetFolder(ThisWorkbook.Path).Files.Count, 1 To 6)
Set cnn = CreateObject("adodb.connection")
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xlsx" Then
n = n + 1
If n = 1 Then cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & File
For i = 1 To 6
SQL = "select f1 from [Excel 12.0;hdr=no;Database=" & File & ";].[DeliveryOrder(Page 1)$" & arr(i) & "]"
Set rs = cnn.Execute(SQL)
brr(n, i) = rs.Fields(0)
Next
End If
Next
ActiveSheet.UsedRange.Offset(1).ClearContents
Range("A2").Resize(n, 6) = brr
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Set Fso = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
2
查看全部评分
-
|