OLE & Excel - Opening causes Excel.exe to hang around

T

TimmyD

This is a very simple script (proof of concept) that simply either
opens an Excel workbook or creates a new one. When I run this script
(with -w of course:) with the Add line uncommented, EXCEL.EXE starts
when the application object is created and closes when the script is
done. However, when I run it with the Open line uncommented, EXCEL.EXE
stays running (in process list) once the script is done. The only way
to get rid of it is to kill it in the Task Manager. Has anyone out
there had this same problem and knows what I'm doing wrong? BTW: I'm
using ActiveState perl v5.8.4

<START CODE>
use Win32::Ole qw(in with);
use strict;
use Cwd;

do_it();

sub do_it() {
my $Excel = "";
my $Book = "";
my $key = "";
my $Sheet = "";
my $current_path = "";
my $full_path_and_filename = "";
my $filename = "";
my @UserStatArray = ();

print "Doing it...\n";
$Excel = Win32::OLE->new( 'Excel.Application',sub { $_[0]->Quit; } )
or die_nice("Couldn't start Excel to read DTC Spreadsheet!");
$current_path = getcwd;
$filename = "blah.xls";
$full_path_and_filename = $current_path.'/'.$filename;

#If the line below (Open) is used, EXCEL.EXE
#stays running (in process list) after the script exits.
#$Book = $Excel->Workbooks->Open($full_path_and_filename,0,1);
#If the line below (Add) is used, EXCEL.EXE
#terminates when the script exits.
$Book = $Excel->Workbooks->Add;

$Sheet = $Book->Worksheets(1);
sleep(1);
$Excel->ActiveWorkbook->Close(0);
$Excel->Quit;
undef $Sheet;
undef $Book;
undef $Excel;
}
<END CODE>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top