Handling different Error 1004 errors

  • Thread starter Thread starter Phil Hibbs
  • Start date Start date
P

Phil Hibbs

If I'm performing actions through an Excel.Application object, the
only error code I get is 1004, which appears to be a generic ODBC
error code. How should I check for more detail on the kind of error
that occurred? All I appear to have is the Err.Description, which I
can check for certain key phrases such as "The macro 'whatever' cannot
be found", or "Check the spelling of the file name", but is there any
other way?

Phil Hibbs.
 
joel said:
You are trying to access an object that doesn't exist.  for example if
you are looking for sheet 1 and your workbook doesn't have a sheet 1

I'm not asking for help with a specific error - there are a whole
spectrum of problems that all trigger Error 1004, and I'm after
general advice on how to identify if a specific one occurs. For
example, in one instance I am calling a macro called FormatSheet in
another workbook, and I know that if that workbook does not have that
macro, it will generate a 1004 error with a Message of "The macro
'FormatSheet' cannot be found." In the event of this error, I want to
just Resume Next, because I don't care that the workbook does not
implement the macro.

My question is, is there another way to detect (for example) a "macro
not found" error other than matching on the Description? That
Description might be very different if, for example, the spreadsheet
is opened on a French copy of Windows and Office.

Phil Hibbs.
 
joel said:
the error methos has a number of properties

....and the Description property is the only one that contains more
info about the nature of the error.

Phil Hibbs.
 
Phil,

the short answer is no.

but in your own example, you know when you get the error at that line, that
the file was not found. So you can anticipate for each particular line of
code what error could occur and you adjust your error handling at each point
to respond accordingly.

Perhaps not what you wanted to hear, but it is pretty much common practice
to proceed the way I have described. I don't think I have ever seen code
where the error description string is parsed to determine the nature of the
error.
 
Back
Top