ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Upon error close workbook (https://www.excelbanter.com/excel-programming/403544-upon-error-close-workbook.html)

robs3131

Upon error close workbook
 
Hi all,

I'm trying to have my spreadsheet automatically close, without saving, upon
an error. Any idea on how to do this? Thanks!

--
Robert

Chip Pearson

Upon error close workbook
 
The code

ThisWorkbook.Close SaveChanges:=False

will close the workbook that contains the code without doing a save. How to
trigger that code, and what you mean by "upon an error", isn't at all clear.
What type of error would you want to intercept? Any VBA runtime error?
Thinking more about this, I would recommend that you not try to do something
like this. There are many, many different errors that may arise in a
workbook, and I suspect that you really only want to act upon a very small
subset of possible errors. It would be very easy to lose a great deal of
work with such a blunt approach.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"robs3131" wrote in message
...
Hi all,

I'm trying to have my spreadsheet automatically close, without saving,
upon
an error. Any idea on how to do this? Thanks!

--
Robert



robs3131

Upon error close workbook
 
Thanks for the code Chip. I'll take your input into consideration.

--
Robert


"Chip Pearson" wrote:

The code

ThisWorkbook.Close SaveChanges:=False

will close the workbook that contains the code without doing a save. How to
trigger that code, and what you mean by "upon an error", isn't at all clear.
What type of error would you want to intercept? Any VBA runtime error?
Thinking more about this, I would recommend that you not try to do something
like this. There are many, many different errors that may arise in a
workbook, and I suspect that you really only want to act upon a very small
subset of possible errors. It would be very easy to lose a great deal of
work with such a blunt approach.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"robs3131" wrote in message
...
Hi all,

I'm trying to have my spreadsheet automatically close, without saving,
upon
an error. Any idea on how to do this? Thanks!

--
Robert




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

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