Run a macro on exit

  • Thread starter More Macro Help Needed
  • Start date
M

More Macro Help Needed

I am looking for a way to have a file run a macro when it is being closed
(the user either hits the X or goes File > Close). I want the macro to check
certain cells and verify if there are values in them. If the cells are blank
then I want an message box to come up saying that all cells are not filled in
and the file remains open. Any help in this area is appreciated. Thanks

Dan
 
F

FSt1

hi
put this in the workbook's before close event

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rng1 As Range
Dim Rng2 As Range
Set rng1 = Cells(1, 1)
Set Rng2 = Cells(2, 1)
If IsEmpty(rng1) Or IsEmpty(Rng2) Then
MsgBox ("Required cells are empty")
Cancel = True
End If
End Sub

edit to fit your data

Regards
FSt1
 
A

Alberto Ast

Good stuff... I want to keep it in my posts so I will reply in addition to
the helpfull check.
 
Top