Most worthy Monks-

I have a perl script, reporter.pl, which opens excel spreadsheets, issues the RefreshAll command to pull the latest data from a db2 database into the spreadsheet, and then mails the resulting updated spreadsheet to the specified user. The script is written in a way that allows any of my coworkers to add a new file to the list of updated files by creating the appropriate directory structure and updating an ini file. This is all done on a windows 2003 server, or XP when testing on my laptop.

A recent feature addition was to allow the user, in the ini file, to specify macros that should be run before and/or after the RefreshAll command. This has introduced an unanticipated (though perfectly obvious) problem: How do I, in my perl script, capture and react to errors caused in the excel macro? Fixing the macros is not always an immediate option and I'm looking for a way to gracefully close down excel and move on to the next report without requiring manual intervention.

I am using Win32::OLE to interface into excel and am able to capture OLE errors without any problem. This does have the unfortunate side affect of preventing me from using Threads or fork, since Win32::OLE is not threadsafe.

I've searched around a bit and everything seems to be telling me how to capture/handle excel and/or ole errors, but not errors that occur within an excel macro. Any help is much appreciated.

In reply to Capturing excel macro errors by jrsimmon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.