Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Win32::IE::Mechanize to download a bunch of Excel files. Because of proxy/firewall issues, I'm stuck with this method.

The problem I'm having is that I can't seem to turn off ALL the warning dialog boxes that pop up when I try to save the displayed Excel file.

So far my code looks more or less like this:

my $spider = Win32::IE::Mechanise->new(); my $agent = $spider->{'Agent'}; my $Excel = Win32::OLE->GetActiveObject ('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{'DisplayAlerts'} = 0; LINE: while (<LINKS>) { ## Read $link and $title from filehandle ## this part works so I've left it out print "Getting link '$link'... "; $spider->get($link); print "ok\n"; print "Saving file as '$title'... "; my $doc = $agent->{'Document'}; $doc->SaveAs($title); print "ok"; }

The document saves fine, and setting DisplayAlerts to false turns off the dialog boxes that pop up then.

But when the script tries to navigate to the next file, or to any other page, another dialog box pops up that says "This document has been modified. Do you want to save your changes?".

This dialog box doesn't seem to be suppressed by either the Excel.DisplayAlerts property, or by the Silent property of the InternetExplorer object.

How do I get this box to go away?

Thanks!

  • Comment on Suppressing dialog boxes in Win32::OLE, InternetExplorer, and Excel
  • Download Code

Replies are listed 'Best First'.
Re: Suppressing dialog boxes in Win32::OLE, InternetExplorer, and Excel
by Anonymous Monk on Mar 09, 2005 at 16:58 UTC

    Well, I solved my own problem.

    In case anyone else encounters a similar issue, all I had to do was call

    $doc->{'Saved'} = 1;

    after calling SaveAs.

    I don't know why calling SaveAs didn't set Saved, nor do I understand why turning DisplayAlerts off didn't suppress the dialog box, but setting Saved did work.

Re: Suppressing dialog boxes in Win32::OLE, InternetExplorer, and Excel
by jplindstrom (Monsignor) on Mar 09, 2005 at 19:34 UTC
    I can tell you that the same problem is present in Office 2000 Word. In that case, there is no way of turning off _any_ popups, and the yes-it-really-is-saved trick was needed to save a document.

    Once you start automating Office it becomes evident pretty early on that it's not very stable or solid and that you are exercising the application in ways that are completely different from human usage patterns. And then things break down in bizarre ways.

    Case in point: Changing the style to the same value it already has causes a "Too complex layout" error after inserting a couple of K text in this way. If you just set the style when it changes, that error goes away.

    /J