|
Sub ADO加数组法()
Dim cnn As Object, rs As Object, SQL$, MyPath$, MyFile$, s$, t$
Dim arr, brr(1 To 65530, 0 To 3), d As Object, i&, j&, m&
Set d = CreateObject("scripting.dictionary")
MyPath = ThisWorkbook.Path & "/"
MyFile = Dir(MyPath & "*.xls")
Do While MyFile <> ""
If InStr(MyFile, ThisWorkbook.Name) = 0 Then
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & MyPath & MyFile
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
If InStr(s, "Sheet1") Then
SQL = "select * from [" & s & "A3:D] where 部门 is not null"
arr = cnn.Execute(SQL).GetRows
For i = 0 To UBound(arr, 2)
m = m + 1
For j = 0 To 3
brr(m, j) = arr(j, i)
Next
Next
End If
End If
End If
rs.MoveNext
Loop
End If
MyFile = Dir()
Loop
ActiveSheet.UsedRange.Offset(3).ClearContents
[a4].Resize(m, 4) = brr
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|