|
- Sub ADO加数组()
- Cells.ClearContents
- tt = Timer
- Dim cnn As Object, SQL$, Mypath$, MyName$, arr, brr(1 To 20000, 0 To 29), i&, j&, m&
- Application.ScreenUpdating = False
- Mypath = ThisWorkbook.Path & ""
- MyName = Dir(Mypath & "*.xls")
- Do While MyName <> ""
- If InStr(MyName, ThisWorkbook.Name) = 0 Then
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.ACE.Oledb.12.0;Extended Properties='Excel 12.0;hdr=NO';Data Source=" & Mypath & MyName
- Set rs = cnn.OpenSchema(20)
- Do Until rs.EOF
- If rs.Fields("TABLE_TYPE") = "TABLE" Then
- s = Replace(rs("TABLE_NAME").Value, "'", "")
- If Right(s, 1) = "$" Then
- SQL = "select * from [" & s & "A8:AB20] WHERE IsNumeric(F1)=TRUE"
- arr = cnn.Execute(SQL).GetRows
- For i = 0 To UBound(arr, 2)
- m = m + 1
- For j = 0 To 27
- brr(m, j + 2) = arr(j, i)
- brr(m, 0) = Split(MyName, ".")(0)
- brr(m, 1) = Left(s, Len(s) - 1)
- Next
- Next
- End If
- End If
- rs.MoveNext
- Loop
- End If
- MyName = Dir()
- Loop
- [A2].Resize(m, 30) = brr
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- MsgBox "用时" & Format(Timer - tt, "0.00") & "秒", 64, "提示"
- End Sub
复制代码 |
|