|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
zhaogang1960 发表于 2014-3-11 13:17
程序1和程序3比较,前者有查询,速度很快,后者只有连接,没有查询,速度很慢
程序3没有查询,当然就不可 ...
是过程1和过程2
Sub ADO加数组已知工作表名_1() '使用Set rs = cnn.Execute(SQL),arr = rs.GetRows
tt = Timer
Dim cnn As Object, rs As Object, SQL$, Mypath$, MyName$, arr, brr(1 To 60000, -1 To 11), i&, j&, m&, n&
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;Data Source=" & Mypath & MyName
SQL = "select * from [Sheet1$a2:l] where 被拆迁人 is not null"
Set rs = cnn.Execute(SQL)
arr = rs.GetRows
For i = 0 To UBound(arr, 2)
m = m + 1
brr(m, -1) = m
For j = 0 To 11
brr(m, j) = arr(j, i)
Next
Next
End If
MyName = Dir()
Loop
[a1].CurrentRegion.Offset(2).ClearContents
[a3].Resize(m, 13) = brr
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
MsgBox Timer - tt
End Sub
Sub ADO加数组已知工作表名_2() 'arr = cnn.Execute(SQL).GetRows
tt = Timer
Dim cnn As Object, SQL$, Mypath$, MyName$, arr, brr(1 To 60000, -1 To 11), i&, j&, m&, n&
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;Data Source=" & Mypath & MyName
SQL = "select * from [Sheet1$a2:l] where 被拆迁人 is not null"
arr = cnn.Execute(SQL).GetRows
For i = 0 To UBound(arr, 2)
m = m + 1
brr(m, -1) = m
For j = 0 To 11
brr(m, j) = arr(j, i)
Next
Next
End If
MyName = Dir()
Loop
[a1].CurrentRegion.Offset(2).ClearContents
[a3].Resize(m, 13) = brr
cnn.Close
Set cnn = Nothing
MsgBox Timer - tt
End Sub
这两个过程比较 |
|