Results 1 to 5 of 5

Thread: closing an excel file opened in VB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904

    closing an excel file opened in VB

    I open an excel file, stuff in some data, close it and kill it.

    everything works fine but the close process brings up a system messge asking if I"d like to save the changes. I'm sure that I've seen a way to make the close process tell the system to save without asking, but now I can't find that technique anywhere in
    the on-line help, so if anyone knows it, I'd appreciate the syntax.

    my close is just:

    xlApp.Workbooks.Close

    and I think it can be something like

    xlApp.Workbooks.Close vbSaveWithoutAsking

    (you get the idea)

    thanks

  2. #2
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247
    I dunno but couldnt you just tell it to save and then to close? Post the code and ill take a look at it.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    couldnt you just tell it to save and then to close?
    I not only could, I do, of necessity. However, the point is that several others in the office use the application and they aren't computer literate and it makes them nervous that the system asks them whether or not to save something. I'd like to automate it.

    The relevant code is:

    VB Code:
    1. Set xlApp = New Excel.Application
    2.     Set xlBook = xlApp.Workbooks.Open(cfg_path & "\" & "template.xls", , True)
    3.     Set xlDataSheet = xlBook.Worksheets("Data")
    4.     Set xlSumSheet = xlBook.Worksheets("Sums")
    5. '
    6. ' push lots of stuff into the spreadsheet
    7. '
    8.     xlApp.Workbooks.Close
    9.     xlApp.Quit
    10.     Set xlApp = Nothing

    Thanks for your time.

  4. #4
    Si_the_geek
    Guest
    Two little bits of code for you:

    close without saving:
    ActiveWorkbook.Close savechanges:=False


    save to specific file:
    ActiveWorkbook.Saveas filename
    (see the help for all the options: file type etc)

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    thanks --- this got me to what I need

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