Closing Excel

J

jim simpson

I need to determine if Excel is running and if so close it. Can this be done
with a Perl script and can someone suggest an approach to do it.

Thanks,

Jim
 
J

Jay Tilton

: I need to determine if Excel is running and if so close it. Can this be done
: with a Perl script and can someone suggest an approach to do it.

#!perl
use warnings;
use strict;
use Win32::OLE;

while(
my $excel =
Win32::OLE ->GetActiveObject('Excel.Application')
) {
$excel ->Quit
}
 
M

Matt Garrish

Jay Tilton said:
: I need to determine if Excel is running and if so close it. Can this be
done
: with a Perl script and can someone suggest an approach to do it.

#!perl
use warnings;
use strict;
use Win32::OLE;

while(
my $excel =
Win32::OLE ->GetActiveObject('Excel.Application')
) {
$excel ->Quit
}

I'd add the warning that the user may not appreciate you closing their
applications. It's generally better practice to warn them that the script
shouldn't be run while Excel (or whatever) is open and bail out.

Matt
 
B

Bob Walton

Jay said:
: I need to determine if Excel is running and if so close it. Can this be done
: with a Perl script and can someone suggest an approach to do it.

#!perl
use warnings;
use strict;
use Win32::OLE;

while(
my $excel =
Win32::OLE ->GetActiveObject('Excel.Application')
) {
$excel ->Quit
}

One might want to include a statement like:

$excel->Application->{DisplayAlerts}='False';

before the ->Quit call if one wishes to ensure Excel actually
shuts down without user intervention (otherwise, one may get a
prompt about saving modified worksheets). This might just apply
to recent versions of Excel (as I recall, a different sequence
was required with Excel 97 and earlier??).
 
J

jim simpson

Thanks to all who responded to my Post.

It works great, of course, and I do need Bob's addition.

Jim
 

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,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top