我在网上找到了此代码以查询Access并将数据输入到excel(2003)中,但是它比它应该慢得多:
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
Run Code Online (Sandbox Code Playgroud)
问题是此代码需要很长时间。如果我打开Access并在其中运行查询,则大约需要1/10的时间。反正有加速的吗?还是这可能需要很长时间?我所有的查询都是简单的select查询,带有简单的where语句,没有连接。甚至select * from [test]查询所花的时间也比它要长得多。
编辑:我应该指定该行
Range(CellPaste).CopyFromRecordset RST
是花了很长时间的那个。
| 归档时间: |
|
| 查看次数: |
17544 次 |
| 最近记录: |