Why does Perl complain about barewords in my Win32::OLE script?

899 Views Asked by At
#___ FIND LAST ROW/COLUMN WITH DATA
my $row = $Sheet1 -> UsedRange -> Find(
     {      What => "*", 
            SearchDirection => xlPrevious,  
            SearchOrder => xlByRows
      })-> {Row};

Error:

Bareword "xlByRows" not allowed while "strict subs" in use. 
3

There are 3 best solutions below

0
On

xlByRows is not a constant, you should put it in quotes. Unless it's a constant exported by the OLE object, in which case you need to import it into your namespace using Win32::OLE::Const or similar.

0
On

You have to put use Win32::OLE::Const 'Microsoft Excel'; at the top of your program to import the constants correctly.

Take a look at this Perl Monks page. It seems to cover the issues you are having.

0
On

See CPAN docs for Win32::OLE::Const

You need to:

use Win32::OLE::Const 'Microsoft Excel';