vbYesNoCancel


Posted by Ed on July 23, 2001 12:05 PM

Hello, Would anyone know how to close a workbook with
clicking the No button on a msgbox. I've got the following
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Check As Integer
Check = Msgbox("Do you want to save the changes")
If Check = vbCancel Then
Cancel = True
Else
If Check = vbYes Then
Blah,Blah,Blah

I need a line of code that by clicking on No" it closes
the the file.
Thanks in advance
Ed



Posted by Dax on July 24, 2001 3:21 AM

Ed,
You can set the Saved propery of the workbook to True. This makes Excel think that there are no changes to save and it will close the workbook without prompting the user with "Do you want to save changes blah blah"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Check As Integer
Check = MsgBox("Do you want to save the changes", vbYesNoCancel)
If Check = vbCancel Then
Cancel = True
ElseIf Check = vbYes Then
ThisWorkbook.Save
'Blah , Blah, Blah
ElseIf Check = vbNo Then
ThisWorkbook.Saved = True
End If
End Sub