ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save If Condition is true (https://www.excelbanter.com/excel-programming/334332-save-if-condition-true.html)

igorek

Save If Condition is true
 
I would like the user to be able to save the file only if the cell A1 is not
empty, else do not save it, and display message "Cannot save"....

Thanks for your help

STEVE BELL

Save If Condition is true
 
With this code in the ThisWorkbook module (using Excel 2000)
You can add or change the criteria.

Caution: my criteria will accept a space in the cell.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
If Len(Worksheets("Sheet1").Range("A1")) = 0 Then
MsgBox "Workbook cannot be saved"
Cancel = True
End If
End Sub

--
steveB

Remove "AYN" from email to respond
"igorek" wrote in message
...
I would like the user to be able to save the file only if the cell A1 is
not
empty, else do not save it, and display message "Cannot save"....

Thanks for your help




KL

Save If Condition is true
 
Hi igorek,

Put the following code inthe ThisWorkbook Module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
If IsEmpty(Worksheets("Sheet1").Range("A1")) Then
Cancel = True
MsgBox "Cannot save..."
End If
End Sub

or

Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
Cancel = IsEmpty(Worksheets("Sheet1").Range("A1"))
End Sub

Regards,
KL


"igorek" wrote in message
...
I would like the user to be able to save the file only if the cell A1 is
not
empty, else do not save it, and display message "Cannot save"....

Thanks for your help





All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com