Thanks for that, BrowserUK. Unfortunately, when I tried SetErrorMode, it didn't help. Mike Rosenblum discussed this in general, in his extremely helpful postings #8 and #11 in the How to Catch An Excel Runtime Error From a WinForm? thread at Xtreme VB Talk. In #8, he says:

As you know, the problem is that VBA does not propagate any exception to the caller when a macro is called by the Excel.Application.Run method. Instead, Excel handles the error locally and displays an error message box to the user.

The only way around this is to not call the Excel.Application.Run method, period. No amount of attempting to tweak the API SetErrorMode() or the like will change anything, because, as far as the external caller is concerned, there is no error. There is no error because VBA handled it by displaying the error message box to the user. As far as I can see, there is no way around this.

So it looks as though this is something it's just not possible to do, via Perl or any other language. The best solution we have is suggested by Mike in #11. That's to call the macros from macros in a workbook object in another instance of Excel (these second macros are methods of the workbook object), and to call those macros from Perl. I show how I made it work in Java, in posting #12.


In reply to Re^2: Win32::OLE: how to call Excel VBA macros and catch all VBA errors without dialog boxes appearing? by popx
in thread Win32::OLE: how to call Excel VBA macros and catch all VBA errors without dialog boxes appearing? by popx

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.