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


In reply to Excel process created with Win32::OLE doesn't quit when expected by ArtYaffe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.