ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close workbook with "Cancel=TRUE" in the BeforeClose()" (https://www.excelbanter.com/excel-programming/313768-close-workbook-cancel%3Dtrue-beforeclose.html)

Wellie[_3_]

Close workbook with "Cancel=TRUE" in the BeforeClose()"
 

I added cVBA code in the "BeforeClose()" event to check to ensure use
would enter mandatory data before existing. If they don't, I keep th
excel open by using the "Cancel=true" command."

I recently found out that users use the Windows Tasks Manager t
terminate the Excel even they know that there are mandtory fields dat
required.

Now, when I run codes data collection VBA codes in my "Master
spreadsheet to collect data from those returned spreadsheets, I ra
into trouble. In my VBA code, after openning the workbook and foun
mandatory data is missing, I stop processing for the opened spreadshee
but I CANNOT open it because of the "BeforeClose()'s cancel=true
statement.

Can someone please tell me how can I close this spreadsheet (one on
with the Cancel=True statment) in my "Master" spreadsheet's VBA ?

Here is log highlevel pseudo-code:

MasterSpreadsheet
{
Open "DataSpreadsheet"
Check for Mandatory data
if ok then
process data and close :) "DataSpreadsheet"
else
close "DataSpreadsheet" :mad: - NOW I cannot clos
it because I have a "Cancel=TRUE" statement inside which found tha
Mandatory data is missing.
endif


--
Welli
-----------------------------------------------------------------------
Wellie's Profile: http://www.excelforum.com/member.php...fo&userid=1537
View this thread: http://www.excelforum.com/showthread.php?threadid=26987


Tom Ogilvy

Close workbook with "Cancel=TRUE" in the BeforeClose()"
 
Application.EnableEvents = False
Activeworkbook.close SaveChanges:=False ' or true
Application.EnableEvents = True

--
Regards,
Tom Ogilvy


"Wellie" wrote in message
...

I added cVBA code in the "BeforeClose()" event to check to ensure user
would enter mandatory data before existing. If they don't, I keep the
excel open by using the "Cancel=true" command."

I recently found out that users use the Windows Tasks Manager to
terminate the Excel even they know that there are mandtory fields data
required.

Now, when I run codes data collection VBA codes in my "Master"
spreadsheet to collect data from those returned spreadsheets, I ran
into trouble. In my VBA code, after openning the workbook and found
mandatory data is missing, I stop processing for the opened spreadsheet
but I CANNOT open it because of the "BeforeClose()'s cancel=true"
statement.

Can someone please tell me how can I close this spreadsheet (one one
with the Cancel=True statment) in my "Master" spreadsheet's VBA ?

Here is log highlevel pseudo-code:

MasterSpreadsheet
{
Open "DataSpreadsheet"
Check for Mandatory data
if ok then
process data and close :) "DataSpreadsheet"
else
close "DataSpreadsheet" :mad: - NOW I cannot close
it because I have a "Cancel=TRUE" statement inside which found that
Mandatory data is missing.
endif
}


--
Wellie
------------------------------------------------------------------------
Wellie's Profile:

http://www.excelforum.com/member.php...o&userid=15370
View this thread: http://www.excelforum.com/showthread...hreadid=269874





All times are GMT +1. The time now is 05:20 PM.

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