View Full Version : Close workbook
Chandrasheka
11-19-2010, 08:14 AM
Hi,
How to reset application.displayalerts to True. because here excel will close then further code will not execute.
How to taggle this?
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
Application.Quit
Else
Application.DisplayAlerts = False
ThisWorkbook.Close False
End If
End If
End Sub
austenr
11-19-2010, 08:25 AM
Maybe:
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
Application.Quit
Else
Application.DisplayAlerts = False
ThisWorkbook.Close False
End If
End If
Application.DisplayAlerts = True
End Sub
Chandrasheka
11-19-2010, 08:33 AM
Hi,
Its shows application display alert. Please let me know why?
Thanks
Chandra Shekar
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
Application.Quit
Else
Application.DisplayAlerts = False
ThisWorkbook.Close False
End If
End If
Application.DisplayAlerts = True
End Sub
Chandrasheka
11-19-2010, 09:45 AM
Any suggestions pls
Bob Phillips
11-19-2010, 09:48 AM
What shows application display alert? Explain more clearly.
Chandrasheka
11-22-2010, 01:55 AM
Hi XLD GA,
Here I am closing active workbook. If worbook count if 1 I am closing whole excel application itself. If workbook count more than 1 I am closing active workbook. Here my problem is
1) I should ignore applications display alerts
2) I should reset application display alerts to true.
In the above code its not happening when it enters last endif again it shows application display alerts whether to save workbook or not. How to come out this. Please let me know.
Thanks
Chandra Shekar
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
Application.Quit
Else
Application.DisplayAlerts = False
ThisWorkbook.Close False
End If
End If
Application.DisplayAlerts = True
End Sub
Chandrasheka
11-22-2010, 08:12 AM
Hi,
Any suggestion pls.
Thanks
Chandra Shekar
Aussiebear
11-22-2010, 11:59 PM
To my way of thinking you need to have the Application.Quit and Workbook close nested inside of the DisplayAlerts False/True statements, not having the DisplayAlerts partly hidden inside of the sub sections.
Charlize
11-23-2010, 12:40 AM
Something like this ?
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
ThisWorkbook.Close False
Application.Quit
Else
ThisWorkbook.Close False
End If
End If
End SubCharlize
you could always nest them nice and tidy but it looks redundant
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
ThisWorkbook.Close False
Application.Quit
Application.DisplayAlerts = True
Else
ThisWorkbook.Close False
Chandrasheka
11-23-2010, 09:28 AM
Hi,
I tried below code if workbook count is 1. Its closing workbook but its not coming to msgbox showing msg "AA" and its not quiting application. Please let me know what is the problem in the code.
Sub Picture80_Click()
conf = MsgBox("Do you want to exit", vbOKCancel, "Confirm to Exit")
If conf = 1 Then
If Workbooks.Count = 1 Then
Application.DisplayAlerts = False
ThisWorkbook.Close False
Application.Quit
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False
ThisWorkbook.Close False
End If
End If
MsgBox "AA"
Application.DisplayAlerts = True
End Sub
Aussiebear
11-23-2010, 02:38 PM
Should you have elipses ( ) around the message?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.