我正在尝试从excel查询访问表。它有效,但它真的很慢。 excel中查询(~60000数据集)的运行时间超过4分钟,访问中的相同查询需要不到两秒钟。不幸的是,我无法使用访问查询,因为在以后的版本中,我将使用参数,这些参数将存储在excel中。也许你们中的某些人对我有一些提示如何改善运行时间?
Sub SQL()
Dim Cn As Object
Dim rs As Object
Dim strSQL As String
Dim strConnection As String
Application.Cursor = xlWait
Set Cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=path.accdb"
strSQL = "SELECT Name,adress,city,street,month,company, sum(amount), sum(price) FROM Table Group by Name, adress,city,street, month, company order by sum(amount) DESC"
Cn.Open strConnection
Set rs = Cn.Execute(strSQL)
Worksheets("Table1").Range("a:x").ClearContents
Worksheets("Table1").Range("a2").CopyFromRecordset rs
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
Application.Cursor = xlDefault
End Sub