ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro on exit (https://www.excelbanter.com/excel-programming/336919-run-macro-exit.html)

More Macro Help Needed

Run a macro on exit
 
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

Tom Ogilvy

Run a macro on exit
 
Use the beforeclose event.

See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"More Macro Help Needed"
wrote in message ...
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




FSt1

Run a macro on exit
 
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
"More Macro Help Needed" wrote:

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


Alberto Ast[_2_]

Run a macro on exit
 
Good stuff... I want to keep it in my posts so I will reply in addition to
the helpfull check.

"FSt1" wrote:

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
"More Macro Help Needed" wrote:

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



All times are GMT +1. The time now is 12:41 PM.

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