Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Youngstown, Ohio, USA
    Posts
    705
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Setting Persistence

    Some time ago, I had asked how to quit Excel without being prompted to save the file. The purpose of this worksheet is, upon opening, to pull variables from another workbook into lines of text, save the result as a text file (.prn), and then quit... all without any intervention. The following VBA code seems to do the trick:
    <hr>Private Sub Workbook_Open()

    ActiveWorkbook.SaveAs Filename:= _
    "C:Program FilesIBMClient AccessEmulatorprivateAutoRpt.prn", FileFormat _
    :=xlTextPrinter, CreateBackup:=False
    Application.DisplayAlerts = False
    Application.Quit

    End Sub
    <hr>

    The suggestion to use Application.DisplayAlerts = False came with the advice to turn the alerts back on immediately before exit sub or end sub. I do not see any way to do this, since the messages I wanted to avoid were being generated due to Application.Quit. Once the quit command is executed, can other VBA commands be processed? Without the opportunity to turn the alerts back on, the next time I open Excel will the alerts still be turned off?

  2. #2
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Persistence

    I don't know if I am missing something here, but the reason why Excel displays a message before the Application.Quit command line is because some open workbook is not saved. As I understood from your post, another workbook is open from which you pull the data into the text file. Close this workbook or save it. If you save every open workbook before quitting, then Excel will not display any messages and you do not need to set displayalerts to false.

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Setting Persistence

    If you are happy that there is no data that you might want saved you could include the following line

    Application.Workbooks.Close

    before

    Application.DisplayAlerts = True
    Application.Quit

    Andrew C

Posting Permissions

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