ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-time error (https://www.excelbanter.com/excel-programming/397496-run-time-error.html)

Francis Hookham

Run-time error
 
Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham



Jim Thomlinson

Run-time error
 
You are correct taht error handling should be used judisciously. That being
said what you are trying to do can be handled safely something like this

OnError Resume Next
ActiveSheet.Names("Print_Area").Delete
ActiveSheet.Names("Print_Titles").Delete
On Error Goto 0

--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham




Francis Hookham

Run-time error
 
You had me guessing for s minute or two - I pasted in your code without
looking carefully at it.

'OnError' in first line! All's well now - many thanks.

Francis

"Jim Thomlinson" wrote in message
...
You are correct taht error handling should be used judisciously. That
being
said what you are trying to do can be handled safely something like this

OnError Resume Next
ActiveSheet.Names("Print_Area").Delete
ActiveSheet.Names("Print_Titles").Delete
On Error Goto 0

--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a
likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham






Jim Thomlinson

Run-time error
 
Error handler (OnError) is ok in this instance because you are ok if it fails
and there is nothing to worry about if it does.

Time to hop on my soap box... The error handler is not there to address poor
code. IMO if you can avoid an error you are much better off than trying to
deal with it after the fact. That being said there are times when your code
may generate errors because you are looking for something that may or may not
exist (such as in your case). You can use the error handler here if either
you don't care if the code fails (such as your case) or you are trying to set
an object that you will check later to see if it was successfully created.
--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

You had me guessing for s minute or two - I pasted in your code without
looking carefully at it.

'OnError' in first line! All's well now - many thanks.

Francis

"Jim Thomlinson" wrote in message
...
You are correct taht error handling should be used judisciously. That
being
said what you are trying to do can be handled safely something like this

OnError Resume Next
ActiveSheet.Names("Print_Area").Delete
ActiveSheet.Names("Print_Titles").Delete
On Error Goto 0

--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a
likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham







Chip Pearson

Run-time error
 
Just adding to Jim's excellent response, it is *critical* to understand that
an On Error does NOT in any way fix the error. I've seen more code than I
care to remember in which the original programmer assumed that On Error
would somehow fix the problem. It doesn't. It just ignores it.


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

"Jim Thomlinson" wrote in message
...
Error handler (OnError) is ok in this instance because you are ok if it
fails
and there is nothing to worry about if it does.

Time to hop on my soap box... The error handler is not there to address
poor
code. IMO if you can avoid an error you are much better off than trying to
deal with it after the fact. That being said there are times when your
code
may generate errors because you are looking for something that may or may
not
exist (such as in your case). You can use the error handler here if either
you don't care if the code fails (such as your case) or you are trying to
set
an object that you will check later to see if it was successfully created.
--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

You had me guessing for s minute or two - I pasted in your code without
looking carefully at it.

'OnError' in first line! All's well now - many thanks.

Francis

"Jim Thomlinson" wrote in
message
...
You are correct taht error handling should be used judisciously. That
being
said what you are trying to do can be handled safely something like
this

OnError Resume Next
ActiveSheet.Names("Print_Area").Delete
ActiveSheet.Names("Print_Titles").Delete
On Error Goto 0

--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a
likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham








Mike[_111_]

Run-time error
 
In message
at 11:54:00 on Fri, 14 Sep 2007, Jim Thomlinson
wrote
Time to hop on my soap box... The error handler is not there to address poor
code. IMO if you can avoid an error you are much better off than trying to
deal with it after the fact. That being said there are times when your code
may generate errors because you are looking for something that may or may not
exist (such as in your case).

A classic example is finding out the ubound of an uninitialised dynamic
array
--
Mike News

Francis Hookham

Run-time error
 
Apologies - time flies - I did not thank you - many thanks

Francis


"Jim Thomlinson" wrote in message
...
You are correct taht error handling should be used judisciously. That
being
said what you are trying to do can be handled safely something like this

OnError Resume Next
ActiveSheet.Names("Print_Area").Delete
ActiveSheet.Names("Print_Titles").Delete
On Error Goto 0

--
HTH...

Jim Thomlinson


"Francis Hookham" wrote:

Run-time error '1004':

Application-defined or object-defined error



this appears when no Print_Area is defined



ActiveSheet.Names("Print_Area").Delete

ActiveSheet.Names("Print_Titles").Delete



I think I have seen that an error message can be turned off before a
likely
error and on again after - dangerous if not carefully used.



How should I handle this possible error?



Francis Hookham







All times are GMT +1. The time now is 12:16 AM.

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