Results 1 to 5 of 5

Thread: Exporting to Excel Sheet

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Exporting to Excel Sheet

    Hi all,

    How can I export my Access Table to Excel Sheet thru VB at runtime.

    Pls guide.

    Regards,
    Prakash

  2. #2
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    Create an instance of Excel, and either use the TransferSpreadsheet method if its just a straight export, or output cell by cell if you need to add in extras (formulas, graphs etc). You'll need to add a ref. to the Excel object library in your project.

    There are zillions of examples of how to do this sort of thing on other threads here. Do a few searches and you should be able to find what you need.

    J.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub ExportOneTable()
    2. Dim strExcelFile As String
    3. Dim strWorksheet As String
    4. Dim strDB As String
    5. Dim strTable As String
    6. Dim objDB As Database
    7.  
    8. 'Change Based on your needs, or use
    9. 'as parameters to the sub
    10. strExcelFile = "C:\My Documents\MySpreadSheet.xls"
    11. strWorksheet = "WorkSheet1"
    12. strDB = "C:\My Documents\MyDatabase.mdb"
    13. strTable = "MyTable"
    14.  
    15. Set objDB = OpenDatabase(strDB)
    16.  
    17. 'If excel file already exists, you can delete it here
    18. If Dir(strExcelFile) <> "" Then Kill strExcelFile
    19.  
    20. objDB.Execute _
    21. "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    22. "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
    23. objDB.Close
    24. Set objDB = Nothing
    25.  
    26. End Sub

  4. #4
    Lively Member
    Join Date
    May 2001
    Location
    A pub that sells Kronenburg
    Posts
    116
    hack,

    thanks for your code is has helped me greatly....

    however is the below line:

    strExcelFile = "C:\My Documents\MySpreadSheet.xls"

    is changed to

    strExcelFile = "C:\My Documents\AA..xls"

    notice the dot after AA

    an error occurs when Select * Into comes into play (invalid bracketing)

    is there any way around this as i need to have . after certain letters (share stock code)

    cheers

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this
    VB Code:
    1. strExcelFile = "C:\My Documents\AA" & Chr(46) & ".xls"
    Chr(46) by the way, is the dot

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