Hi, I am using excel 2003 Active Perl 5.8.8 Build 817 and cannot get the UsedRange syntax (as Per Perl Monks tips example) to work. When I use Strict I fail with a run time compile error for xlprevious. When I don't use Strict I get a type mismatch error on SearchDirection. When I initially installed the OLE module I also got a version control issue and had to change the OLE.PM hard coded version from 1704 to 1403.

I can confirm that excel is installed as I can perform other excel functions ... it mainly seems related to the xlnnnnn type parameters. I previously had success with this code with different version of excel and active state perl 5.6.

Please Help.

This is the essence of my code

#!C:/Perl/bin/perl use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use Win32::OLE qw(in valof with); use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... my $DateFormat = "DDD mmm dd, yyyy -- hh:mm:ss"; # Directory to store uploaded customer files my $uploadc_dir = "E:/Inetpub/wwwroot/someplace/somefilelib"; my $query = new CGI; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{DisplayAlerts}=0; my $IBook = $Excel->Workbooks->Open("E:\\afile"); # select worksheet number 1 (you can also select a worksheet by name) +and activate it my $ISheet = $IBook->Worksheets(1); $ISheet->Activate(); # Find last row and last column my $LastRow = $ISheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; my $LastCol = $ISheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByColumns})->{Column};

Edited 2 Apr 2006 (~21:30 PDT) by footpad: Added rudimentary formatting tags.


In reply to Win32:OLE UsedRange error 0x80020005: "Type mismatch" by Anonymous Monk

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.