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

VISUAL BASIC WORKBOOK BEFORE SAVE EVENT 1

Status
Not open for further replies.

STRATMAN1

Programmer
Jun 17, 2004
19
US
I am trying to use the Workbook BeforeSave Event (if appropriate) to prevent an excel worksheet from saving if a particular cell does not equal the number 1. Cant seem to get it to work. I also would like a message box that pops up if the value of this cell is not 1, but no yes/no choice is necessary: only info that the file wont save if the value in this cell is unequal to 1. All advice on code solution very much appreciated.Thanks, Stratman1
 
Without seeing the code you are currently using it is hard to see what may not be working for you. But this should help you in the direction.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = (Range("A1") <> 1)
If Cancel Then
MsgBox "Workbook Cannot Be Saved", vbInformation, "Cannot Save"
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top