Two possibilities I would check.  First, you forgot to check whether the
Excel object was properly created.  Second, 'or' has a lower precedence than
assignment, so 

        $Excel = Win32::OLE->GetActiveObject('Excel.Application') or
Win32::OLE->new('Excel.Application', 'Quit');

is equivelant to

        ($Excel = Win32::OLE->GetActiveObject('Excel.Application)) or
(Win32::ELE->new('Excel.Application', 'Quit'));

You want to use '||' instead.

Try this:

        my $Excel = Win32::OLE->GetActiveObject('Excel.Application') 
                || Win32::OLE->new('Excel.Application', 'Quit');
        croak("error accessing Excel OLE server: ", Win32::OLE->LastError)
unless defined $Excel;


HTH,
Ian 

> -----Original Message-----
> From: Jeffrey [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 11, 2002 2:49 PM
> To: Perl win32
> Subject: OLE errors
> 
> 
> I have written a large number of scripts using OLE and
> Excel, but I'm getting something strange now.
> 
> Here are the relevant portions of the script:
> $Excel = Win32::OLE->
> GetActiveObject('Excel.Application') or Win32::OLE->
> new('Excel.Application', 'Quit'); # This is one line
> 
> $Excel->Workbooks->Open("$path\\$short_name.xls",3)
> or warn "Cannot open $path\\$short_name.xls ",
> Win32::OLE->GetLastError(); # This is one line
> 
> $path and $short_name are both defined properly.  The
> error I am getting is "Can't call method "Workbooks"
> on unblessed reference at
> C:\Documents\Perl\PSC_id_Comparison\Compare_PSC.plx
> line 98.", line 98 corresponding to the Open line
> above.
> 
> I'm using AS perl v5.6.1 build 631.  Fresh install
> over build 630, where I got the same errors.  Other
> scripts that use these commands still work fine.  This
> is a new script, meaning that I typed everything in
> properly (no hidden garbage characters), but these are
> commands I have used many many times.
> 
> Does anyone have any insightful or generally useful
> ideas?  I'm stumped.
> 
> =====
> ------------------------------------
> Jeffrey Hottle
> nkuvu at yahoo dot com
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
> 
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to