Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
run time error 1004 general odbc error excel 2003 vba | Excel Programming | |||
Run Time 1004 Error: Application or Object Difine Error | Excel Programming | |||
Conditional Formatting - Run Time Error '13' Type Mismatch Error | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming | |||
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error | Excel Programming |