I've found Excel OLE to be quirky like this. My pseudo subclass suddenly stopped working due to this error, I found it was because the order of operations had changed.
I made sure the following global operations happened before any book level or worksheet level op. happened.
my $ex = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
if (not defined $ex) {
die "couldn't get an instance of Excel";
}
$ex->{DisplayAlerts}=0;
$ex->{SheetsInNewWorkbook} = 1;
$ex->{Visible} = 0 ;
$Win32::OLE::Warn = 3; # Die on Errors.
| [reply] [d/l] |
I'm writing a script which opens each excel file in a directory, reads some values from the workbook, then closes the workbook, and I had the same problem of Excel quitting when I closed the workbook.
The inspiration came when I noticed the problem did not happen if I manually opened Excel first (with the default, blank "Book1")
The work-around I used was to create a new workbook first, process all the files, (open, close, open, close...) then close my "KeepOpen" workbook when I was all done:
$KeepOpen = $Excel->Workbooks -> Add;
# your code / loop here
$KeepOpen -> Close;
Hope this helps,
-- zaaj
| [reply] [d/l] |
Thank you very much, this worked for me!
| [reply] |