Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Cancel a Save or Close Event 1

Status
Not open for further replies.

sooner2

MIS
Jul 13, 2006
2
US
I need to be able to cancel a Save and Close event.
After a user has entered his data on a sheet, I have a beforesave and beforeclose event that validates the entire spreadsheet. If I find errors, I need to be able to stop the save or close from completing.

Any suggestions?
 
Take a look at the Cancel property of those events. :)

I.e. If Condition = True Then Cancel = True

HTH

-----------
Regards,
Zack Barresse
 
I tried that and it did not seem to work. I may have done something wrong but the save/close was executed.

Since this code is in the beforesave / beforeclose event, would it not only end that event.

How would I send the actual "save" or "close".

 
Please post your code and list out what conditions should end with which result(s).

-----------
Regards,
Zack Barresse

Simplicity is the ultimate sophistication.
- Leonardo da Vinci
 
Put it this way, here are some examples...


Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Msg As VbMsgBoxResult
    Msg = MsgBox("Do you really want to close?", vbYesNo, "Close?")
    If Msg <> vbYes Then
        Cancel = True
    End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim Msg As VbMsgBoxResult
    Msg = MsgBox("Do you really want to save?", vbYesNo, "Save?")
    If Msg <> vbYes Then
        SaveAsUI = False
        Cancel = True
    End If
End Sub


HTH

-----------
Regards,
Zack Barresse

Simplicity is the ultimate sophistication.
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top