jjxia2001
asked on
How to code to stop saving Excel workbook in "Workbook_BeforeSave"
I added some codes inside "Workbook_BeforeSave" to check something. If not meeting my requirements, I used "Exit Sub". But the workbook was still saved. Is anyway I can stop saving process?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error GoTo Errorhandler
If Range("AccountNumber") = "" Then
MsgBox ("Please enter SAI Number")
Range("AccountNumber").Sel
Cancel = True
Exit Sub
End If
If Range("PolicyEffectiveDate
MsgBox ("Please enter Policy Effective Date")
Range("PolicyEffectiveDate
Cancel = True
Exit Sub
End If
Dim bln As Boolean
bln = UserHasAccess()
If bln Then
Call getUserID
frmWaitBox.Show modal
subRemoveCloseButton frmWaitBox
frmWaitBox.Repaint
Call Driver
Unload frmWaitBox
Exit Sub
Else
MsgBox ("Archiving of responses failed - possibly because you are offline. Your Knowledge Edge results are still valid.")
Exit Sub
End If
Errorhandler:
MsgBox ("Archiving of responses failed - possibly because you are offline. Your Knowledge Edge results are still valid.")
lngMessResult = SendErrorEmail("Error" + " contains one or more invalid range references")
End Sub