before close event with condition

M

mohavv

I'm a bit familiar with workbook event Workbook_BeforeClose.

I only want to run a msgBox if cell G2 has a certain value
(unbalanced) when the workbook is closed.

How can I do this?

Cheers,

Harold
 
D

Dave O

I'm a bit familiar with workbook event Workbook_BeforeClose.

The only code you'd need is this line in the Workbook_BeforeClose:
if range("g2").value = "unbalanced" then msgbox("This analysis does
not balance.")

Please try that, and let us know if you require anything else.

Dave O
Eschew Obfuscation
 
M

mohavv

The only code you'd need is this line in the Workbook_BeforeClose:
if range("g2").value = "unbalanced" then msgbox("This analysis does
not balance.")

Please try that, and let us know if you require anything else.

Dave O
Eschew Obfuscation

This works ok. Thanks!

Is there also a way to create the msgbox with a cancel option to be
able to go back and change the sheet.

Cheers,

Harold
 
D

Dave O

No, once you click the X or click >File >Close the file is going to
close. You might set up another event to warn the user, such as On
Save, or set the file so that cell A1 of every tab is painted red
until the analysis is balanced.
 
G

Gord Dibben

Dave

Incorrect.

You can stop the closing of workbook.

See other posts in this thread.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top