|
请参考:- Sub ADO加字典法()
- Dim cnn As Object, rs As Object, SQL$, MyPath$, MyFile$, s$, t$
- Dim arr, brr(1 To 65530, 0 To 2), 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
- SQL = "select * from [" & s & "] where 物品 is not null"
- arr = cnn.Execute(SQL).GetRows
- For i = 0 To UBound(arr, 2)
- t = arr(0, i) & arr(1, i)
- If Not d.Exists(t) Then
- m = m + 1
- d(t) = m
- For j = 0 To 2
- brr(m, j) = arr(j, i)
- Next
- Else
- brr(d(t), 2) = brr(d(t), 2) + arr(2, i)
- End If
- Next
- End If
- End If
- rs.MoveNext
- Loop
- End If
- MyFile = Dir()
- Loop
- ActiveSheet.UsedRange.Offset(1).ClearContents
- [a2].Resize(m, 3) = brr
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|