Link to home
Start Free TrialLog in
Avatar of jjxia2001
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
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jjxia2001
jjxia2001

ASKER

I added it in and didn't work.  See my code below.


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").Select
        Cancel = True
        Exit Sub
        End If
   
        If Range("PolicyEffectiveDate") = "" Then
        MsgBox ("Please enter Policy Effective Date")
        Range("PolicyEffectiveDate").Select
        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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial