|
楼主 |
发表于 2014-3-12 17:22
|
显示全部楼层
百度不到去谷歌 发表于 2014-3-12 17:14
哎哟 还没结果呢 受不起啊 我有新的发现 不过还没完整的测试模型 可能有突破
现在可以把问题集中在问题3上面第一种情况,第一次连接数据库时,Set rs =……随便一个简单查询,速度就很快
- Sub ADO加数组已知工作表名_31() '第一次连接工作簿,把查询赋值给变量
- tt = Timer
- Dim cnn As Object, SQL$, Mypath$, MyName$, rs As Object, m As Byte
- 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
- If m = 0 Then
- ' Set rs = cnn.OpenSchema(20) 'adSchemaTables
- Set rs = cnn.Execute("select * from [Sheet1$a2:l] where 1=2")
- m = 1
- End If
- End If
- MyName = Dir()
- Loop
- cnn.Close
- Set cnn = Nothing
- MsgBox Timer - tt
- End Sub
复制代码 第二种情况,仅有连接:
- Sub ADO加数组已知工作表名_32() '仅连接工作簿,不做任何操作
- 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
复制代码
|
|