ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   before close event with condition (https://www.excelbanter.com/excel-discussion-misc-queries/166819-before-close-event-condition.html)

mohavv

before close event with condition
 
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

Dave O

before close event with condition
 
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

mohavv

before close event with condition
 
On Nov 21, 9:59 am, Dave O wrote:
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


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

Dave O

before close event with condition
 
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.

Gord Dibben

before close event with condition
 
Dave

Incorrect.

You can stop the closing of workbook.

See other posts in this thread.


Gord Dibben MS Excel MVP

On Tue, 20 Nov 2007 17:53:49 -0800 (PST), Dave O wrote:

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.




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

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