VBA: Querying Access with Excel. Why so slow?

后端 未结 10 631
情话喂你
情话喂你 2021-01-18 03:24

I found this code online to query Access and input the data into excel (2003), but it is much slower than it should be:

Sub DataPull(SQLQuery, CellPaste)
Dim         


        
10条回答
  •  无人及你
    2021-01-18 03:54

    If you retrieve a lot of records, it would explain why the Range(CellPaste)takes so long. (If you execute the query in Access it wouldn't retrieve all the records, but if you do the CopyFromRecordset it requires all the records.)

    There is a MaxRows parameter for CopyFromRecordset:

    Public Function CopyFromRecordset ( _
        Data As Object, _
         MaxRows As Object, _
         MaxColumns As Object _
    ) As Integer
    

    Try if settings this to a low value (like 10 or so) changes the performance.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题