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

Hi,
for($i=0;$i<5;$i++){ $slide = $ppt->Slides->Add($i, ppLayoutBlank); } $pname = 'C:\Documents and Settings\ \Desktop\Perl_files\fall.gif'; $Slide->Shapes->AddOLEObject({Left=>225, Top=>125, Width=>480, Height=>320, FileName=>$pname});
I am getting an error wen i run the code like "cant Call method Shapes" can any one please help me in loading a pic in Powerpoint. I have tried using the previous posts but still it is givin the same error.

Replies are listed 'Best First'.
Re: powerpoint problem
by NetWallah (Canon) on Apr 24, 2008 at 18:24 UTC
    • Please use code tags to show your code : see Writeup Formatting Tips
      Update: O.P has since done this. Thanks.
    • Please use strict; - that would have pointed out your error (below)
    • $Slide is different from $slide. In your code, $Slide is not defined.

    FYI, your "while ($i < 5)" loop can be written more idiomatically thus:

    for (my $i = 1; $i < 5; $i++) { $slide = $ppt->Slides->Add($i, ppLayoutBlank); }

         "How many times do I have to tell you again and again .. not to be repetitive?"

      I think that loop would be even more clear this way:

      foreach my $i ( 1 .. 4 ) { $slide = $ppt->Slides->Add($i, ppLayoutBlank); }
        Agreed. (++)

        To take it to the next step, how about:

        $slide = $ppt->Slides->Add($_, ppLayoutBlank) for 1..4;
        and avoid the (explicit) pesky temporary variable.

        However, for newbies, I'd suggest they stay with my original "C-style for loop" suggestion (to use when they actually need the index variable), until they get more comfortable with perl-style use of $_ for temp vars, and lists generated by the ".." operator.

             "How many times do I have to tell you again and again .. not to be repetitive?"

      my problem is not wid the loop, I just sent a part of my code. The main problem is I couldnt paste the ".gif" file in my PPT slide.
      $pname = 'C:\Documents and Settings\Desktop\Perl_files\file.gif'; $slide->Shapes->AddOLEObject({Left=>225, Top=>125, Width=>480, Height=>320, FileName=>$pname});
      It is just pasting a text "file.gif" instead of picture. So is there any way I can import the picture..??
        In addition to pc88mxer's advice below, you need to use the AddPicture method (instead of AddOLEObject) to add a picture from a file.

        Thank you for using <code> tags. Perhaps you could edit your original node, and add those, to assist new readers of this thread.

             "How many times do I have to tell you again and again .. not to be repetitive?"

Re: powerpoint problem
by pc88mxer (Vicar) on Apr 24, 2008 at 18:53 UTC
    Not only as NetWallah points out are perl variables case-sensitive, i.e. $splice is different from $Splice, but you need to manipulate your newly created slide inside the while/for loop:
    $pname = "..."; for my $i (0..4) { $slide = $ppt->Slides->Add(...); $slide->Shapes->AddOLEObject(...); }