|
ADO法速度很快,请参考:
- Sub ADO法()
- Dim Fso As Object, File As Object, cnn As Object, rs As Object, SQL$, m&, arr()
- Set Fso = CreateObject("Scripting.FileSystemObject")
- ReDim arr(1 To Fso.GetFolder(ThisWorkbook.Path).Files.Count, 1 To 2)
- For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
- If File.Name Like "*.xlsx" Then
- m = m + 1
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & File
- Set rs = cnn.Execute("[Sheet1$a2:a2]")
- arr(m, 1) = rs.Fields(0)
- Set rs = cnn.Execute("[Sheet1$g41:g41]")
- arr(m, 2) = rs.Fields(0)
- End If
- Next
- ActiveSheet.UsedRange.Offset(1).ClearContents
- If m > 0 Then [a2].Resize(m, 2) = arr
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- Set Fso = Nothing
- End Sub
复制代码 |
|