Pankaj
Pankaj

Reputation: 61

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

#___ 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. 

Upvotes: 3

Views: 901

Answers (3)

gdey
gdey

Reputation: 141

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.

Upvotes: 4

denkfaul
denkfaul

Reputation: 331

See CPAN docs for Win32::OLE::Const

You need to:

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

Upvotes: 4

Andrew Barnett
Andrew Barnett

Reputation: 5174

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.

Upvotes: 1

Related Questions