You don't tell us what you're really trying to do. It appears that you are trying, in this code, to read every file in a directory that has a certain extension (I use 2002 so I have a different extension in a variable) and print its name. I have based the following code, which works for me, on Re^5: Win32::OLE Excel search and replace commas.

use strict; use warnings; use Cwd; use Win32::OLE; my $ext = ".xls"; my $Excel=Win32::OLE->new('Excel.Application'); $Excel->{Visible}=1; $Excel->{DisplayAlerts}=1; #Set to 0 when the code is working, but +keep at 1 while debugging. my $dir = getcwd; $dir =~ s/\//\\\\/g; #Sort out the slashes and backslashes opendir(DIR, $dir) or die "can't opendir $dir: $!"; #Cookbook recipe 9 +.5 while (defined(my $file = readdir(DIR))) { if ((!-d $file) and (substr($file, -length($ext)) eq $ext)) { +#Someone WILL call a directory something.xls. I have the scars. my $Book = $Excel->Workbooks->Open("$dir\\\\$file") or die "Ca +n't open file $dir\\\\$file"; print $Book->FullName . "\n"; $Book->Close; } } closedir(DIR); $Excel->Quit;

The output in my command window is:

Z:\Data\Perl>922394.pl Z:\Data\Perl\WhichMonk.xls Z:\Data\Perl>cd\excel\sudonkey Z:\Excel\Sudonkey>\data\perl\922394.pl Z:\Excel\Sudonkey\SuDonkey2.xls Z:\Excel\Sudonkey\SuDonkey.xls Z:\Excel\Sudonkey\SuDonkey1_0_3.xls Z:\Excel\Sudonkey\InPlay.xls Z:\Excel\Sudonkey>

I am left with no orphan instance of Excel. It works on any directory. Please try this. If it leaves an orphan instance, then it's down to a 2007 parameter and without a copy, I can't help you further.

Regards,

John Davies


In reply to Re^5: MS Excel 2007 never dies - or at least the process wont by davies
in thread MS Excel 2007 never dies - or at least the process wont by otism

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.