Com Exceptions from Excel

Blair Hall b.hall at irl.cri.nz
Wed Jul 10 21:31:01 EDT 2002


I would appreciate some advice in how to use information about
COM exceptions generated from MS Excel.

Based on "Python: programming on win32", Ch 12, p212
I have written the following exception handler

def comExceptionHandler(e) :

    hr,msg,exc,arg = e
    sys.stderr.writelines( 'COM call failed: (HRESULT=%s) %s\n' %
(hr,msg) )
    if (arg != None and arg != -1): sys.stderr.writelines( 'Argument:
%s\n' % arg )
    if exc != None:
        wcode, source, text, helpFile, helpID, scode = exc
        sys.stderr.writelines(  'Error wcode=%s scode=%s\n' %
(wcode,scode) )
        sys.stderr.writelines(  'Error source: %s \n' % source )
        sys.stderr.writelines(  '%s \n' % text )
        sys.stderr.writelines(  'See also: %s (id=%d) \n' %
(helpFile,helpID) )

The information this gives is hard to deal with.
For example, I have an instance of MS Excel open and I try to
save the current workbook,
            wb.SaveAs(filename)
Lets say filename identifies a file that exists already, so Excel asks
me with a dialog box if I want to overwrite or not. I click
on 'No' and an exception is raised. The handler above produces
the following mesage:

COM call failed: (HRESULT=-2147352567) Exception occurred.
Error wcode=1004 scode=0
Error source: Microsoft Excel
SaveAs method of Workbook class failed
See also: XLMAIN8.HLP (id=0)

My problem is that I can't figure out how the numerical error code
relates to the MS Help files. I realise that the HRESULT value
is DISP_E_EXCEPTION (from the win32 book), but how does
wcode or scode relate to the Excel documentation? I can find nothing
in either XLMAIN.hlp or VBAXL8.hlp to shed light on this!

Obviously it would be nice to identify  types of error so
that appropriate action can be taken! In this case, change the
file name.




More information about the Python-list mailing list