Results 1 to 5 of 5

Thread: Copy large data from Access to Excel *SOLVED*

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Copy large data from Access to Excel *SOLVED*

    I have about 5000 records I need to copy into an existing excel spreadsheet from an Access table. I have tried the below but it is way to slow. Does any one know of a much quicker way I can paste the 5000 records into Excel?

    Thanks.

    Code:
    Do Until rsSelectedTrades.EOF = True
    objExcel.Cells(RowActive, 80).Value = rsSelectedTrades!ShareCode 'Column 80 is CB
    objExcel.Cells(RowActive, 81).Value = rsSelectedTrades!StockTradeNo
    objExcel.Cells(RowActive, 82).Value = rsSelectedTrades!EntryDate
    objExcel.Cells(RowActive, 83).Value = rsSelectedTrades!Enter
    objExcel.Cells(RowActive, 84).Value = rsSelectedTrades!Direction
    objExcel.Cells(RowActive, 85).Value = rsSelectedTrades!Exit
    objExcel.Cells(RowActive, 86).Value = rsSelectedTrades!HoldPeriod
    objExcel.Cells(RowActive, 87).Value = rsSelectedTrades!Profit
    objExcel.Cells(RowActive, 88).Value = rsSelectedTrades!ProfitPer
    objExcel.Cells(RowActive, 89).Value = rsSelectedTrades!Other
    objExcel.Cells(RowActive, 90).Value = rsSelectedTrades!Signal
    objExcel.Cells(RowActive, 91).Value = rsSelectedTrades!ExitDate 'Column 91 is CM
    
    rsSelectedTrades.MoveNext
    objExcel.ActiveCell.Offset(1, 0).Select
    RowActive = RowActive + 1
    Loop
    Last edited by lintz; Mar 22nd, 2004 at 02:26 AM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    You can do that using Access automation:
    VB Code:
    1. Private Sub ExportExcelSheet(strMdbPath As String, _
    2.                              strExcelPath As String, _
    3.                              strTable As String)
    4. '======================================================
    5. Dim AccessDB As Access.Application
    6.  
    7.     Screen.MousePointer = vbHourglass
    8.     Set AccessDB = New Access.Application
    9.     AccessDB.OpenCurrentDatabase strMdbPath
    10.     AccessDB.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
    11.                                        strTable, strExcelPath, True
    12.     AccessDB.Quit acQuitSaveNone
    13.     Set AccessDB = Nothing
    14.     Screen.MousePointer = vbDefault
    15.  
    16. End Sub

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Thanks RhinoBull, i'll give it a try.

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    I was up against something similar. CopyFromRecordset (Excel 2000+)
    may be an option for you.

    Here was my situation (see the last post) here.




    Bruce.

  5. #5

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Bruce, that link worked a treat. Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width