Ok, I have a simple data table in sql server. In vba I'm selecting a subset of records, and I want those to go into an excel sheet.
I'm currently doing something like
This works, but is very slow--like 10 seconds for 500 20-field records. Since this is a relatively simple set of data, isn't there a way to write the recordset to one big string variable, maybe with delimiters and line-breaks, and then copy that string to clipboard and paste to the excel.worksheet? Or some way, any way, to just overlay the recordset data right into excel without having to do it cell-by-cell?
I've thought about excel's import/export routines, or an odbc-link, but it seems like the overhead of that might be high. One of the things to consider here is that the recordset is already open for another part of the process, so that time is a freebie--the data is there already and just needs to splat into Excel. So any odbc-links or imex routines from the excel object would likely have to create their own recordset which would add cost.
Maybe the .Range method is the wrong choice? What would be faster?
Thanks for any guidance,
--Jim
I'm currently doing something like
Code:
...<dim and set all excel.app objects, open file,open rs etc>
Do Until rs.eof
lCount = lCount + 1
for i = 1 to rs.fields.count '(skipping first field; <26 fields)
objExcel.Range(chr(64 + i) & lCount) = rs(i).value
next i
rs.movenext
loop
I've thought about excel's import/export routines, or an odbc-link, but it seems like the overhead of that might be high. One of the things to consider here is that the recordset is already open for another part of the process, so that time is a freebie--the data is there already and just needs to splat into Excel. So any odbc-links or imex routines from the excel object would likely have to create their own recordset which would add cost.
Maybe the .Range method is the wrong choice? What would be faster?
Thanks for any guidance,
--Jim