|
请参考:
- Sub ADO加数组法()
- Dim cnn As Object, SQL$, p$, f$, a, arr, brr#(), i&, j&, n&
- arr = Range("A3:A" & Range("A" & Rows.Count).End(xlUp).Row)
- ReDim brr(1 To UBound(arr), 0 To 6)
- p = ThisWorkbook.Path & ""
- Set cnn = CreateObject("ADODB.Connection")
- For i = 1 To UBound(arr)
- f = p & arr(i, 1) & "" & arr(i, 1) & "【汇总预算】.xls"
- If Dir(f) <> "" Then
- n = n + 1
- If n = 1 Then cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties=excel 12.0;Data Source=" & f
- SQL = "select * from [Excel 12.0;hdr=no;Database=" & f & "].[A1$D15:J15]"
- a = cnn.Execute(SQL).GetRows
- For j = 0 To 6
- If Not IsNull(a(j, 0)) Then brr(i, j) = a(j, 0)
- Next
- End If
- Next
- [b3].Resize(i - 1, 7) = brr
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|