Consulting

Results 1 to 5 of 5

Thread: Solved: transferspreadsheet method

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    Solved: transferspreadsheet method

    I am using the following to export query results from Access to Excel

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Hello", "C:\data\phil.xls"

    However it says it cant find the objext phil.xls

    When I replace this with a new book i.e. Book4.xls which is closed it works OK and creates a new sheet with the same name as the query and drops in the data.

    When I put the code in Book4 and point it at phil.xls as long as phil.xls is closed it works.

    Why is this happening.

    Also rather than having it create a new sheet is there any way I can make it paste the data into an existing sheet in phil.xls each time I run the code

    Any help would be appreciated

    Thanks

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Are you running the code from Phil.xls?
    You don't get that much control using TransferSpreadsheet - you would need to automate Excel from Access or use ADO (or DAO) from Excel to get the data and drop it into a worksheet.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    It isn't clear wheter you run your code from access or excel...anyway
    here an article about all the methods to transfer data from access to excel so that you can see how use ADO and DAO.

    http://www.zmey.1977.ru/Access_To_Excel.htm

    You could use the copyfromrecordset method to transfer data while file is open. I haven't tried but it should work.

    Regards
    ALe
    Help indigent families: www.bancomadreteresa.org

  4. #4
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    transferspreadsheet

    Thanks for that link it was very helpful

    My code is in Excel so if there is a similar link to help from an Excel point of view that would be great

  5. #5
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    code can be executed from excel as well as from access. Just make a reference in excel to the access library to use access objects and methods.
    ALe
    Help indigent families: www.bancomadreteresa.org

Posting Permissions

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