in reply to Using Excel in Perl failure after OS re-install

use OLE is a compatibility layer for applications using the old toplevel OLE.pm. # New code should use Win32::OLE. Try

#!perl use strict; use Win32::OLE::Const "Microsoft Excel"; printf "Perl %s\n",$^V; printf "Win32::OLE Version %s\n",$Win32::OLE::VERSION; my $excel = Win32::OLE->new('Excel.Application') or die Win32::OLE->LastError(); printf "Excel %s\n",$excel->{'version'}; print "excel <$excel>\n"; $excel->{Visible} = 1; my $workbook = $excel->Workbooks->Add or die Win32::OLE->LastError(); print "workbook <$workbook>\n"; my $sheet = $workbook->Worksheets("Sheet1"); $sheet->Activate; print "sheet <$sheet>\n";
poj

Replies are listed 'Best First'.
Re^2: Using Excel in Perl failure after OS re-install
by merrymonk (Hermit) on Mar 03, 2019 at 14:29 UTC
    Thank you
    I tried you suggestion but got the following error on the failing PC

    Perl v5.28.0

    Win32::OLE Version 0.1712 Win32::OLE(0.1712) error 0x800401f3: "Invalid class string" at line with my $excel = Win32::OLE->new('Excel.Application') or die Win32::OLE->LastError();

    However on the PC where the test works, you suggestion also works.
    The Perl version and Win32:OLE version were the same on both PCs.

    Have you any idea why the systems are giving different results?

      Do both PCs have the same version of Excel ?

        ..good question!
        I have just realised that on the failing PC the line
        printf "Excel %s\n",$excel->{'version'};
        gave nothing at all - however on the successful PC I got Excel 14.0
        I used the same disc for both PCs (I am in the process of replacing the old PC for a new one).
        On both PCs Excel is stored in same directory .../Office14.
        Therefore I thought I had but one does not seem to be 'recognised'.
      ...an update If i remove the last section of the $excel line so that it is
      my $excel = Win32::OLE->new('Excel.Application') ;
      it does not give the Class error but neither does it work.