Excel Vba Copyfromrecordset Slows When Copying Over 100 Columns
i'm trying to use the code below to copy data from a sql (2008 r2) table to multiple sheets in excel 2003 - there are currently c420000 records, expanding at around 1000 a week. t
Solution 1:
You can usually get quite a reasonable speed with ADODB like so:
''The data source z:\docs\test.accdb is not used, it is only there to get a
''working string.
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=z:\docs\test.accdb"
cn.Open strCon
''This selects into an existing workbook with a new sheet name, any name that does
''not already exist will work. The ODBC connection to SQL Server is whatever you
''use for ODBC connection.
ssql = "SELECT * INTO [Excel 8.0;HDR=YES;DATABASE=Z:\Docs\Test.xlsx].[Sheet7] " _
& "FROM [ODBC;DRIVER=SQL Server Native Client 11.0;SERVER=localhost\SQLEXPRESS; " _
& "DATABASE=MyDB;Trusted_Connection=Yes;].MyTable"
cn.Execute ssql
Post a Comment for "Excel Vba Copyfromrecordset Slows When Copying Over 100 Columns"