application.quit issue

Kempes

Registered User.
Local time
Today, 09:12
Joined
Oct 7, 2004
Messages
327
Hi all,

I've had a quick look around but couldn't find the answer.

My VB code starts with

application.displayalerts = false

then, further down the code

application.quit

finishing with

application.displayalerts = true

However, It still asks me if I want to save the spreadsheet, even though displayalerts = false.

Is there any way around this?
 
Can you post your code please. Displayalerts is the correct property to prevent the save as dialog from appearing so I'm guessing something else is happening.
 
This is the jist of it.

Application.DisplayAlerts = False

If Range("AY11") = 1 Then
Range("B2,B4,B6,B8,B10,B12,B14,B38,B40,B42,B44,B46,B48,B50,B52").Value = ""
Worksheets(1).Unprotect Password:="xxxx"
Range("AY11").Value = 2
Worksheets(2).Unprotect Password:="xxxx"
ThisWorkbook.Sheets(2).Range("P1:P10").Value = ""
ThisWorkbook.Sheets(2).Range("T1:T15").Value = ""
Run ("macro9")
description.Value = ""
Benefits.Value = ""
Run ("macro6")
Range("B4").Select
Me.Submit.Visible = True
MsgBox ("success")
ActiveWorkbook.SaveAs "path.xls"
Application.Quit
Else
Application.Quit
End If

Application.DisplayAlerts = True

I have found something that I am looking at now which is.

Thisworkbook.saved = true

placed within the before_close section.

But still not sure why displayalerts = false failed.
 
the thing I am having trouble with is the 'application.quit'.

Once you quit the application you can't do anything else so your Application.DisplayAlerts = True isn't doing anything. if this code is being used by other people you might really piss them off by quitting the application like that.

Try removing application.quit and try this:

Code:
ActiveWorkbook.SaveAs "path.xls"
activeworkbook.close
 
Ahh actually it does seem to pick up on the setwarnings bit when you run the code. if you put a breakpoint on the application.quit line and then step through it ignores the code afterwards and just quits the application but picks up on the following lines when you just run it. Anyway application.quit is best avoided when the code resides within the application you are running it from just close the objects you want to.
 
Oh and watch out when saving, if when you save you have display alerts set to false then when you reopen that workbook then display alerts will still be false.
 
I didn't know that! Well worth knowing.

The before_close event did the trick by the way.
 

Users who are viewing this thread

Back
Top Bottom