Results 1 to 4 of 4
  1. #1
    b82726272 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2014
    Posts
    21

    Data update Access to Excel

    Hi,



    I want to update data in an Excel sheet with an Access query. I have the code below. The deletion of the sheet works fine. The transfer of the query data not because the Excel file is open. How can I solve this? Thank you in advance.

    Kind regards,

    Code:
    Dim wb As Excel.Workbook
        Dim xlApp As Excel.Application
        ' Delete old data in Excel
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        Set wb = xlApp.Workbooks.Open("C:\Excel1.xlsx", True, False)
        wb.Sheets("Query1").Delete
        ' Export data to Excel
        DoCmd.TransferSpreadsheet acExport, 10, _
        "Query1", "C:\Excel1.xlsx", True

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Open the workbook AFTER the transfer.
    If you want it in a specific sheet, put the sheet name AFTER the true param.
    DoCmd.TransferSpreadsheet acExport, 10, "Query1", "C:\Excel1.xlsx", True, "Sheetname"

  3. #3
    b82726272 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2014
    Posts
    21
    Hi ranman256,

    Thank you for the reaction. How can I open the workbook after the transfer? I get an error when I place the open statement after the transfer.

    Kind regards,

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Its already in your code...
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    Set wb = xlApp.Workbooks.Open("C:\Excel1.xlsx", True, False)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-16-2014, 07:07 AM
  2. Update records on only ONE FIELD from excel data?
    By stildawn in forum Import/Export Data
    Replies: 3
    Last Post: 11-19-2013, 04:55 PM
  3. Import access query data into excel file, using excel vba
    By exceljockey in forum Import/Export Data
    Replies: 3
    Last Post: 11-15-2013, 02:36 PM
  4. SQL Update query using data in Excel column
    By tylerg11 in forum SQL Server
    Replies: 2
    Last Post: 09-03-2013, 05:10 PM
  5. Code to Update Excel from Access
    By portmancp in forum Programming
    Replies: 2
    Last Post: 03-10-2010, 03:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums