+ Reply to Thread
Results 1 to 4 of 4

Save changes prompt when I am shutting down the computer.

  1. #1
    Registered User
    Join Date
    11-28-2012
    Location
    vienna
    MS-Off Ver
    Excel 2010
    Posts
    3

    Lightbulb Save changes prompt when I am shutting down the computer.

    Hello everyone,

    I ve tried:
    Private Sub Workbook_BeforeClose(cancel As Boolean)

    Application.EnableEvents = False
    ThisWorkbook.Save
    Application.DisplayAlerts = False
    Application.Quit

    End Sub



    It works fine when pressing X to the program but shutting down the computer give me the "save question".

    I am using Office 2010.

    Is there any other code I can try in Workbook_BeforeClose or even catch the" windows shutting down" somehow to run a sub?

    thanks in advance

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,424

    Re: Save changes prompt when I am shutting down the computer.

    Perhaps try it in this order:

    Please Login or Register  to view this content.

    I don't know if that will fix it but I'm working on the basis that the last thing you want to do before closing is to save the workbook. Putting the DisplayAlerts before the save shouldn't hurt and it means there's no activity between the save and the quit.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-28-2012
    Location
    vienna
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Save changes prompt when I am shutting down the computer.

    Hello,

    thanks for your responce. I ve tried your code but unfotunately the message comes. I believe that the windows shutdown is stopping/pausing the VBA causing the " Private Sub Workbook_BeforeClose(cancel As Boolean) " not to run.
    I was thinking, maybe it is possible to use the wm_queryendsession to prevent windows shutdown, save and exit workbook and then shutdown(or restart) the computer. My problem I m quite new to VBA programming and do not know how to do that.
    Can someone help me with that? or anyone any other idea?

    Thanks again

  4. #4
    Registered User
    Join Date
    11-28-2012
    Location
    vienna
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Save changes prompt when I am shutting down the computer.

    Hello,

    I found time to experiment a bit on this issue today and found out that if I make a Doevents after Application.Quit it works...But not in all files!
    In one file where the code is relative small it works (this is actually my test code where I am doing the experiments to find a solution to the problem).
    On the file where the code is much longer it doesn't work- I assume when the code is long, the reaction time of excel is slower...

    still looking for an answer...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1