Hi, esr. The general way of trapping error conditions in Perl, which I assume works in Win32::OLE programming as well, is eval blocks. So I would replace your call to $excel->ActiveWorkbook with a subroutine that looked something like (untested):

sub isWorkbookActive { my ($excel) = @_; eval { return $excel->ActiveWorkbook; }; return 1 if $@ =~ /message filter/; }

But frankly, you will more likely find a more specific (and less Perl-dependent) solution at the MSDN site (look here for starters). Any sample code you find will probably be in VB, but it should translate easily enough. Also look in the section of Win32::OLE's POD about Office. Update: Apparently the answer is more complex than that. Did you see the reply to one of your recent nodes that pointed to Trapping errors with Win32::OLE?

As a total aside, I must comment, esr, on your choice of username. I probably wasn't the only Monk who thought for a moment that you might be ESR of OSI/Cathedral and the Bazaar/fetchmail fame. It seems rather unlikely, given that the other ESR is neither a Win32 programmer nor an especially great fan of Perl, but it's still amusing. Update: ESR is not an opponent of Perl either, by any means. His full assessment is here.


In reply to Re: Checking when Excel editing is done by Errto
in thread Checking when Excel editing is done by esr

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.