I run an Excel process as a scheduled task on a W7 PC. I think that during a recent MicroSoft Office update there was a change to Excel. I used to be able to open a new Excel process with:
use Win32::OLE qw(in with); my ($ex, $book, %WS); my $Exname="$ENV{USERPROFILE}\\Documents\\ABC.xls"; # Always use a new instance of Excel so as to not interfere with anyth +ing open on the desktop $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; # Set Application Visibility; 0 = Not Visible, 1 = Visible $ex->{'Visible'} = 0; # 'Not Visible' is the default, but set it anywa +y $ex->{DisplayAlerts}=0; $book = $ex->Workbooks->Open($Exname); $WS{$book->Worksheets(1)->{name}}=$book->Worksheets(1); ############################# # # # Work happens here # # # ############################# $book->Close; Win32::OLE->Uninitialize; undef $book; undef $ex;
After a recent Windows Update, the Open($Exname) fails unless
$ex->{'Visible'}=1;I changed the 'Visible' state to 1 and also added these two lines before the Open($Exname):
use constant xlMinimized => -4140; $ex->{'WindowState'} = xlMinimized; # the window will be momentarily v +isible anyway
This works and is almost satisfactory (the Excel window flashes the screen very briefly), but now sometimes the Excel process remains as an orphan process after the Perl script has ended. I tried putting a substantial sleep time after the
$book->Close;but it didn't help. Has anyone else seen this? Any other suggestions to try? This is perl, v5.8.9 built for MSWin32-x64-multi-thread
Thanks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |