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

Hi Monks, I am using Excel via Win32::OLE and getting complaints when Excel is not already running. My code (with compliments and thanks to previous posts here at PerlMonks) includes:

# check if Excel exists my $x = Win32::OLE->GetActiveObject('Excel.Application'); if ($@) { warn "Excel not Installed.\n"; die "Excel not Installed.\n"; } # start Excel program, die if unable to unless (defined $x) { $x = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit; } ) # and # sleep 1 or warn "Cannot start Excel.\n" and die "Cannot start Excel.\n"; } $x->{DisplayAlerts}=0; # no messages from Excel

When Excel had NOT been running for some time, the above produced an error message of:

Win32::OLE(0.1502) error 0x80010105: "The server threw an exception" in PROPERTYPUT "DisplayAlerts" at /PerlApp/xls_subs.pl line 110

which corresponds to the "$x->{DisplayAlerts}" line above. However, running the same chunk of code again, changing nothing, raised no exceptions. And so it seems that I'm getting hung up by an initialization process for Excel, that, once loaded in RAM, doesn't affect me again. Is uncommenting these lines

# and # sleep 1
the right approach or is there a way to wait until Excel is good and ready before proceding? Thanks.

Replies are listed 'Best First'.
Re: Initialization process exceptions with Excel; Win32::OLE
by ff (Hermit) on Oct 24, 2003 at 03:49 UTC
    Hmm, well, digging around Microsoft shows some info that I include in the "ReadMore." Since I'm running W2K and doing my thing locally, I seem to be a candidate for this problem. It looks like implementing their workaround solution would have to happen within the Win32::OLE module? Their direct solution of installing the Service Pack appears irrelevant since I'm already at SP4, which came out 6/2003... Hmm.