|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub ADO加数组_汽油_购进_带票_汇总()
tt = Timer
[B3:Z1048576] = ""
Dim cnn As Object, SQL$, Mypath$, MyName$, arr, brr(1 To 4, 1 To 10), i&, j&, m&
Application.ScreenUpdating = False
Mypath = ThisWorkbook.Path & "\"
MyName = Dir(Mypath & "*.xlsx")
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
If InStr(s, "入") Then
SQL = "select * from [" & s & "] "
arr = cnn.Execute(SQL).GetRows
For i = 0 To UBound(arr, 2)
If InStr(arr(1, i), "汽") And arr(5, i) = "是" Then
For j = 4 To 4
brr(1, j - 3) = brr(1, j - 3) + arr(j, i)
Next
End If
Next
End If
End If
End If
rs.MoveNext
Loop
End If
MyName = Dir()
Loop
[B3].Resize(1, 1) = brr
cnn.Close
Set cnn = Nothing
Application.ScreenUpdating = True
MsgBox "用时" & Format(Timer - tt, "0.00") & "秒", 64, "提示"
End Sub |
|