Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Great Monks,

I m getting error as

Can't call method "Open" on an undefined value at gui.pl line 45.

use Win32::OLE::Const 'Microsoft Excel'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application'); ####$pet is some.xls file##### my $Book = $Excel->Workbooks->Open($pet) or die ("not opened $pet\n"); + my $Sheet = $Book->WorkSheets("Sheet1");

Replies are listed 'Best First'.
Re: win32::OLE doubt.
by tachyon (Chancellor) on Aug 02, 2004 at 09:18 UTC

    The creation of your $Excel object is failing. You don't check for this or the *sometimes* informative OLE error message. In fact I expect the error message will be a less than helpful one in this case. GetActiveObject will fail if there is not an instance of Excel already running with an error message of '0'. Try:

    my $Excel = Win32::OLE->new("Excel.Application" , sub { $_[0]->Quit } +) or die Win32::OLE::LastError; $Excel->{Visible} = 1;

    cheers

    tachyon

      tachyon,

      Thanks for your reply. Now i m getting it alright.

      Once again, thanks for ur reply.