-
Da_Silvy
This looks like a useful piece of code. I am wondering if you know what to put in this sub to stop it from closing. I mean sth like the equivalent of "Exit Sub" in VB.
What I want to do should look like this:
If Worksheets("Sheet1").Cells("A1").Value <> "" Then
MsgBox("You have data in cell A1. The program can't close.")
Exit Sub ' stops the close
End If
Is that possible?
-
try this on for size:
in the editor, click on ThisWorkbook
then add this code:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Sheets("Sheet1").Range("A1").Value <> "" Then
MsgBox ("You have data in cell A1. The program can't close.")
Cancel = True
End If
End Sub
How did that work?