I am trying to read a directory of files, and if they are excel files (.xls extension) with a particular naming convention, work certain magic(tm) on them. The problem is, if I use regex to determine validity, and combine the path info with the filename info and push it into an array for later use, when I try to open the .xls file in excel, I get the following error:

OLE exception from "Microsoft Excel":
Unable to get the Open property of the Workbooks class
Win32::OLE(0.1101) error 0x800a03ec
in METHOD/PROPERTYGET "Open" at fileopen.pl line XX
So..I simplified my problem down to the following :

Please note that if I create the array like so:

@array = ('somepath', 'someotherpath',...,'somefinalpath');

instead of using the regex method, everything works hunky dory, but as soon as I try to use the values in the array built by the combination of the path info + the filename info. Nada, nothing, no dice.

I'm running Active Perl 522 on Win2k. Ideas?

Thanks again for your help...I'm truly stumped.

Chuck. ------
use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $mypath = 'c:\perl\projects'; my $elem = ""; my $filetype = "xls"; my @files; if (opendir CURRDIR, $mypath){ @allfiles = readdir CURRDIR; closedir CURRDIR; } for my $elem (0..$#allfiles){ if ($allfiles[$elem] =~ /^[\d\w\s]+\.$filetype/) { $cfile = "$mypath\\$allfiles[$elem]"; push (@files,$cfile); } } my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Qui +t'); # @files = ('c:\perl\projects\letterdist.xls', 'c:\perl\projects\freqs +.xls'; #Use this instead of above regex, below works fine for my $x (0..$#files){ printf "%-s\n",$files[$x]; my $Book = $Excel->Workbooks->Open($files[$x]) || die " $! "; # op +en Excel files #my $Book = $Excel->Workbooks->Open('c:\perl\projects\LetterDist.x +ls') || die " $! "; # open Excel files #This works fine $Book->Close(); }

In reply to Using Win32::OLE 'Excel' and stumped by cacharbe

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.