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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't save Excel spreadsheet if errors found. 1

Status
Not open for further replies.

JazzyLee

Programmer
Jan 24, 2002
47
US
Is there a way to warn a user that there are errors on a spreadsheet when trying to save it and then stop the save process? I would like to keep the spreadsheet from being saved until all required fields have valid data in them. I am working on Excel 2000.
 
Add the BeforeSave procedure to the workbook so you can check the required fields before allowing the save:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  
  Dim blnErrors As Boolean

  'code to check input...

  If blnErrors = True
    
    MsgBox "An error was detected, please try again."
    Cancel = True

  End If
End Sub

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Thanks for the info. I almost had it working by the time I got this response. This cleared up what I was NOT doing right and of course, helped me in adding a call subroutine to the BeforeClose trigger. Now I have my Excel sheet holding for correction even if the "X" is clicked. What would we do without "WIZARDS" like you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top