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

Hi all,
use Win32::OLE; use Win32::OLE::Const 'Microsoft Office'; use Win32::OLE::Const 'Microsoft PowerPoint'; for($a=1;$a<3;$a++) { $power = Win32::OLE->GetActiveObject('Powerpoint.Application') || Win32::OLE->new('Powerpoint.Application', 'Quit'); $ppt = $power->Presentations->Add(); $ppt->{visible}=1; $xlapp = Win32::OLE->new('Excel.Application'); if($a==1) { $file = 'C:\fg\IMS\Chart for SW.xls'; $name = 'Chartsppt'; } else { $file = 'C:\fg\IMS\dms_data\Summary.xls'; $name='Summaryppt'; } $book = $xlapp->Workbooks->Open("$file"); $xlapp -> {Visible} = 1; for($i=1;$i<15;$i++) { $sheet = $book -> Charts($i); $sheet->Activate; $slide = $ppt->Slides->Add(1, ppLayoutBlank); $slide->Shapes->AddOLEObject({Left=>100, Top=>125, Width=>580, Height=>380, FileName=>$file ,}); } $filename = 'C:\fg\dms_data'; $ppt->SaveAs($filename . $name .'.ppt'); $ppt->Quit; $xlapp->Quit; }
In the above code I am getting multiple results(and errors). Some time I could able to extract both the Excel Sheet into Powerpoint and some time I can extract just one xls and for the next one(xls) I got an Error "Can't call method "AddOLEObject" on an undefined value at C:\fg\Chartppt.pl line 37." and some time I got an error like "Can't call method "Activate" on an undefined value at C:\fg\Chartppt.pl line 24." Can any one please tell me why is it happen like that and how to over come this kind of errors. Thanks, Shaggy

Replies are listed 'Best First'.
Re: Error in powerpoint extraction
by olus (Curate) on May 01, 2008 at 14:14 UTC

    At first glance, those two messages do not seem to originate from the same source code, as there are only 2 lines between Activate and AddOLEObject.

    I'm not familiar with the modules you're using, but still, a possible cause for the error may be related to the files not having 15 charts, and you are looping all the time for that amount of charts. Look for some method that gives you the amount of such elements in a sheet.

      You were write the number of charts differs in different Excel workbooks. Thanks for the correction. :-)