Results 1 to 3 of 3
  1. #1
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38

    How to edit Excel from Access

    I am trying to edit an Excel file from Access. If possible, I do not want Excel to be visible during the edit process. Below is the code I wrote but it does not Save the changes and I get the message "ZPP_BOM Extract.XLSX is locked for editing" when I try to look at the Excel file. I am not sure what I am doing wrong.



    Sub ChangeExcel4()
    Dim MySheetPath As String
    Dim XlApp As Excel.Application
    Dim XlBook As Excel.Workbook
    Dim XlSheet As Excel.Worksheet


    MySheetPath = "C:\Users\Downloads\BOM Extract.xlsx"


    Set XlApp = CreateObject("Excel.Application")
    Set XlBook = XlApp.Workbooks.Open(MySheetPath, , False)


    Set XlSheet = XlBook.Sheets("Sheet1")
    XlSheet.Activate


    XlSheet.Range("A1") = "Test"


    XlBook.Save
    XlBook.Close
    XlApp.Quit
    Set XlApp = Nothing
    Set XlBook = Nothing
    Set XlSheet = Nothing
    End Sub

    Thanks.
    Sandy

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Try:

    Set XlApp = CreateObject("Excel.Application")
    Set XlBook = XlApp.Workbooks.Open(MySheetPath, , False)
    Set XlSheet = XlBook.Sheets("Sheet1")
    XlSheet.Range("A1") = "Test"
    XlBook.Close savechanges:=True
    XlApp.Quit
    Set XlApp = Nothing
    Set XlBook = Nothing
    Set XlSheet = Nothing
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38
    Thank you. The code worked after I restarted my computer.

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

Similar Threads

  1. Replies: 11
    Last Post: 12-21-2023, 04:05 AM
  2. Replies: 2
    Last Post: 12-17-2017, 09:04 PM
  3. Edit Excel using Access VBA
    By Mjz in forum Programming
    Replies: 3
    Last Post: 06-08-2017, 01:40 PM
  4. Replies: 1
    Last Post: 10-16-2016, 10:15 AM
  5. Access Opens Excel, Edit, SaveAs, then Close
    By jadown in forum Programming
    Replies: 6
    Last Post: 03-09-2015, 09:50 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