|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub a()
Dim cnn As Object, rs As Object, SQL$, Mypath$, MyName$, arr, brr(1 To 30000, 1 To 1), i, m As Integer, d
Set d = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
Mypath = ThisWorkbook.Path & "\"
MyName = Dir(Mypath & "*.xls")
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=NO';Data Source=" & Mypath & MyName
SQL = "select * from [sheet1$a4:b10] "
Set rs = cnn.Execute(SQL)
arr = rs.getRows
For i = 0 To UBound(arr, 2)
m = m + 1
brr(m, 1) = arr(0, i)
d(brr(m, 1)) = d(brr(m, 1)) + arr(1, i)
Next
End If
MyName = Dir()
Loop
[a4].Resize(d.Count, 1) = Application.Transpose(d.keys)
[b4].Resize(d.Count, 1) = Application.Transpose(d.items)
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Set d = Nothing
Application.ScreenUpdating = True
End Sub |
|