|
- Sub ADO加数组复习()
- t = Timer
- Dim Fso As Object, File As Object, cnn As Object, rs As Object, SQL$, m&, arr()
- Set Fso = CreateObject("Scripting.FileSystemObject")
- ReDim arr(1 To Fso.GetFolder(ThisWorkbook.Path & "\混凝土报告").Files.Count, 1 To 12)
- For Each File In Fso.GetFolder(ThisWorkbook.Path & "\混凝土报告").Files
- If File.Name Like "*.xls" Then
- m = m + 1
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & File
- Set rs = cnn.Execute("[1$G4:K4]")
- arr(m, 1) = Mid(rs.Fields(0), 6, 20) & rs.Fields(4)
- Set rs = cnn.Execute("[1$C5:C5]")
- arr(m, 2) = rs.Fields(0)
- Set rs = cnn.Execute("[1$B12:K12]")
- arr(m, 3) = rs.Fields(1)
- arr(m, 4) = rs.Fields(0)
- arr(m, 8) = rs.Fields(2)
- arr(m, 9) = rs.Fields(9)
- End If
- Next
- ActiveSheet.UsedRange.Offset(3).ClearContents
- If m > 0 Then [a4].Resize(m, 12) = arr
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- Set Fso = Nothing
- MsgBox Timer - t
- End Sub
复制代码 |
|