none
Closing a .csv file programatically RRS feed

  • Question

  • Using Access 2003 SP3

    My program copies a .csv template file to a new file, them using the Excel object model, opens the new .csv file and populates it with the appropriate data.

    The problem I have is in closing the file. In Excel, after saving a .csv file then choosing File>close, or clicking the close X in the upper right corner, Excel always responds with the redundant

    "Do you want to save the changes you made to 'EPICBX09.csv'?"
    [Save] [Don't Save] [Cancel].

    Unfortunately, this also happens after the code:

    objExcel.Workbooks(1).Save
    objExcel.Workbooks().Close
    Set objExcel = Nothing

    If my Excel object is invisible it never closes because it is waiting for an answer to the above redundant question.

    If my Excel object is visible then the user has to answer the redundant question.

    Is there a way to force Excel to close the file without going through the extra 'close' question?

    Thanks in advance for any help.  --fred

    Wednesday, September 14, 2016 5:02 PM

Answers

  • Replace the lines

    objExcel.Workbooks(1).Save
    objExcel.Workbooks().Close

    with

    objExcel.Workbooks(1).Close SaveChanges:=True


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Fredrated451 Wednesday, September 14, 2016 8:53 PM
    Wednesday, September 14, 2016 7:04 PM

All replies

  • Replace the lines

    objExcel.Workbooks(1).Save
    objExcel.Workbooks().Close

    with

    objExcel.Workbooks(1).Close SaveChanges:=True


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Fredrated451 Wednesday, September 14, 2016 8:53 PM
    Wednesday, September 14, 2016 7:04 PM
  • Thanks Hans, your suggestion did the trick!
    Wednesday, September 14, 2016 8:55 PM