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

Good day, monks!
Below is a part of my code.
use Win32::OLE; $Excel = Win32::OLE->GetActiveObject ('Excel.Application')|| Win32::OL +E->new('Excel.Application', 'Quit'); $Book = $Excel->Workbooks->Open($restrictfile) ; my $Sheet = $Book->Worksheets(1);

The problem is that when I use computers with office 2000 to execute the code I get this error message.
"Tk::Error: Can't call method "Worksheets" on an undefined value".
On computers with office 2003 everything works fine.I tried on few computers with different office version (2000/2003). Does anyone know how to overcome this issue? Thanks in advance.

20040709 Edit by ysth: Changed title from 'working with WIN32::OLE'

Replies are listed 'Best First'.
Re: Problems with Win32::OLE and different Office versions
by JamesNC (Chaplain) on Jul 07, 2004 at 11:16 UTC
    The problem is with the path used $restrictfile. I get your error if my path is wrong, make sure you use the full absolute path.(eg 'c:\\myfiles\\test.xls') Excel defaults to My Documents when it calls Open() vs the local directory your are executing your script from.

    JamesNC

      I've also found that even though Perl can handle forward slashes as path delimiters, Excel can't. For example:

      # ... other code before this ... if (-e "c:/myfiles/test.xls") { # We get here just fine, but... $Book = $Excel->Workbooks->Open("c:/myfiles/test.xls") or die "Hork!\n"; # Dies }
Re: Problems with Win32::OLE and different Office versions
by PodMaster (Abbot) on Jul 07, 2004 at 08:26 UTC
    $Excel = Win32::OLE->GetActiveObject ('Excel.Application')|| Win32::OL +E->new('Excel.Application', 'Quit') || die "EEEEEEEEEEEEEK: Can't create Excel.Application : Do you have M +icrosoft Excel installed? : $! : $^E";

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks PodMaster-it doesn't help.The application doesn't die here.
      If I append "die" to the next line of code:
      $Book = $Excel->Workbooks->Open($restrictfile)|| die "EEEEEEEEEEEEEK: +Can't create Excel.Application : Do you have M +icrosoft Excel installed? : $! : $^E"; ;
      it dies only on computer with office 2000 and says "No such file or directory" , although if office 2003 installed -everything works fine.