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

W

Wellie

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
 
T

Tom Ogilvy

Application.EnableEvents = False
Activeworkbook.close SaveChanges:=False ' or true
Application.EnableEvents = True
 

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