Sub DataPull(SQLQuery, CellPaste)
Dim Con As New ADODB.Connection
Dim RST As New ADODB.Recordset
Dim DBlocation As String, DBName As String
Dim ContractingQuery As String
If SQLQuery = "" Then
Else
DBName = Range("DBName")
If Right(DBName, 4) <> ".mdb" Then DBName = DBName + ".mdb"
DBlocation = ActiveWorkbook.Path
If Right(DBlocation, 1) <> "\" Then DBlocation = DBlocation + "\"
Con.ConnectionString = DBlocation + DBName
Con.Provider = "Microsoft.Jet.OLEDB.4.0"
Con.Open
Set RST = Con.Execute(SQLQuery)
Range(CellPaste).CopyFromRecordset RST
Con.Close
End If
End Sub
这段代码的问题在于运行时间非常长。如果我在Access中打开并运行查询,只需要大约1/10的时间。有办法可以加快速度吗?或者可能有任何原因导致这个查询需要这么长时间吗?我的所有查询都是简单的select查询,带有简单的where语句和无连接。即使是
select * from [test]
查询所需要的时间也比应该多得多。编辑:我应该指出那一行代码
Range(CellPaste).CopyFromRecordset RST
需要很长时间。