|
ADO法请参考:- Sub Macro1()
- Dim cnn As Object, SQL$, MyPath$, MyFile$, n%, arr, brr(1 To 60000, 1 To 6), i&, c, d As Object
- Set d = CreateObject("scripting.dictionary")
- arr = [a1].CurrentRegion
- For i = 3 To UBound(arr, 2) Step 2
- d(arr(1, i)) = i
- Next
- MyPath = ThisWorkbook.Path & ""
- MyFile = Dir(MyPath & "*.xls")
- Application.ScreenUpdating = False
- Do While MyFile <> ""
- If MyFile <> ThisWorkbook.Name Then
- n = n + 1
- If n = 1 Then
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='excel 8.0;hdr=no';Data Source=" & MyPath & MyFile
- SQL = "select * from [Sheet1$]"
- Else
- SQL = "select * from [Excel 8.0;hdr=no;Database=" & MyPath & MyFile & ";].[Sheet1$]"
- End If
- arr = cnn.Execute(SQL).GetRows
- brr(n, 1) = Replace(MyFile, ".xls", "")
- For i = 1 To UBound(arr)
- c = d(arr(i, 0))
- If c <> "" Then
- brr(n, c) = arr(i, 1)
- brr(n, c + 1) = arr(i, 2)
- End If
- Next
- End If
- MyFile = Dir()
- Loop
- ActiveSheet.UsedRange.Offset(2).ClearContents
- [a3].Resize(n, 6) = brr
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|