Trying to understand why Perl Win32 OLE Excel Server threw an exception

0

Trying to understand and diagnose what is wrong with my Excel setup on a MS server 2008. See MWE below. This works fine on my Win laptop but not so great on server. From clean login it runs ok the first time, but subsequent runs fail with error text:

Win32::OLE(0.1709) error 0x80010105: "The server threw an exception"
    in PROPERTYPUT "DisplayAlerts" at mwe.pl line 20

The first run leaves excel.exe in the task manager. The second run I suppose is trying to reattach to this existing instance but failing. How can I understand what is going wrong please?

Alternatively, how can I kill off the Excel process started by Win32::OLE when the script has finished so a re-run starts a new instance?

My MWE:

use strict;
use warnings;

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # Die on Errors.

# use existing instance if Excel is already running
my $Excel;
eval {$Excel = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;

unless (defined $Excel) {
   print "another\n!";
   $Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
            or die "Oops, cannot start Excel";
}

$Excel->{DisplayAlerts}=0;

$Excel->Quit();
undef $Excel;
perl
excel
exception
win32ole
asked on Stack Overflow Mar 28, 2013 by Chris

1 Answer

0

Can you try with $Excel->{'DisplayAlerts'} = 0 with the quotes? I use it that way and it works. I guess all references are made this way.

answered on Stack Overflow May 21, 2013 by Susithra

User contributions licensed under CC BY-SA 3.0