in reply to Powerpoint OLE

The following Works okay for me:
use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; #Must Be capitalized to load constants--^ my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; my $Presentation = $PptApp->Presentations->Open({FileName=>'<SOMEFIL +ENAME>',ReadOnly=>1});

Now, please notice that the constants line REQUIRES you to use a capital, but the GetActiveObject and new do not necessarily require capitalization.

I have a sinking suspicion your problem lies in how you utilizied Open.

Hope this helps.

Quick Note: Also, you can't pass True, It's a type mismatch (You gotta flip the bool bit with an integer, which is different than flipping the bozo bit, but sometimes, not by much)

C-.

Replies are listed 'Best First'.
Re: Re: Powerpoint OLE
by smithwt (Initiate) on Sep 09, 2001 at 18:05 UTC
    Thanks Rich / C-... I can now open a given Powerpoint file. I ran the code you sent me and it opens an existing ppt file. My next (and most frustrating) Perl challenge is to select a given slide, then paste an Excel chart to the slide. I also need to properly size the chart, but I think that will become trivial if I can just get over the first hill. The perl / Excel side of the problem is already functioning, with my code copying the Excel chart to the clipboard. I've captured a number of Powerpoint macros that do the required functions (slide select, copy, size, et al.) and tried to convert them to Perl to no avail. Does anyone have an end-to-end example of a functioning Perl / Powerpoint app that I can study? I have raided every bookstore in town and have a Perl library at least 3 feet wide. Unfortunately, the Win32 / OLE sections concentrate on Excel, with some mention on Word and Outlook. I have yet to see anything on Powerpoint. If I ever figure it out, maybe I'll write that first Perl / Powerpoint book. If this were just a hobby I'd attack the problem differently, spending the time to get a full indoctrination in OLE. Unfortunately, I'm under the gun to produce an automation product involving Powerpoint in the next week for work. Any thing you can do will be a great help! Bill
      It looks to me (Just from reading your post, and looking at what little code you've provided) that you're a little confused about using this particular object model. You should post some of the things you have tried, and maybe we can help you out.

      So you get an idea of the syntax, I pounded this out this morning over coffee while I caught up on week-end email.

      use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; $Win32::OLE::Warn = 3; # Die on Errors my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| +Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; my $Presentation = $PptApp->Presentations->Add(); #my $Presentation = $PptApp->Presentations->Open({FileName=>'<SOMEFILE +NAME>',ReadOnly=>1}); my $Slide = $Presentation->Slides->Add({Index=>1 , Layout=>ppLayoutTex +t}); $Slide->{Name} = "Slide1"; my $TextBox=$Slide->Shapes->AddTextbox({Orientation=>1, Left=>5, Top=>5, Width=>250, Height=>250,}); $TextBox->TextFrame->TextRange->{Text} ="Big Ole Test"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Title Test"; my $NewSlide = $Slide->Duplicate(); $NewSlide->{Name} = "Slide2";

      I would suggest that you start PowerPoint and leave it running without any active presentations so that you can watch what is going on. Also, look again at how I call methods that require multiple inputs (Hash format vs. List format), and you need to pay close attention to what certain methods and functions return when called.

      C-.

        Hello there monks,
        After a couple days of "harsh" work, I finally managed to read text included in powerpoint slides. It may be of use to any of you working with Powerpoint. It also shows how to easily access PPT's properties. So here are the bits and pieces of code. I'll write a snippet with a complete function and program to access Powerpoint some time soon...
        package readPowerPoint; use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; use Win32::OLE::Const 'Microsoft Office'; use Data::Dumper; require Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(readActivePPT); sub readActivePPT # this method returns the name of the active PPT, its content and a ha +sh # the PPT's properties we consider to be useful. Hence it is ready fo +r use { if ( my $powerpoint = Win32::OLE->GetActiveObject('Powerpoint.Appli +cation')) # connect to powerpoint application { if (defined (my $activePPT=$powerpoint->ActivePresentation)) { my $PPTName = $activePPT->Name; # retrieve PPT name i.e. subj +ect my $PPTProperties = $activePPT->{BuiltInDocumentProperties}; my %PPTContent = (); # read PPT content - see below for struc +ture details for my $slideNumber(1..$activePPT->{Slides}->Count) { my $total = $slideNumber / $activePPT->{Slides}->Count; print "\n---------------- Please wait (".100*$total."% don +e)----------------"; my $slide = $activePPT->slides($slideNumber); if ($slide->{Shapes}->Count) { for my $shapeNumber(1..$slide->{Shapes}->Count) { if ( ($slide->shapes($shapeNumber)->HasTextFrame()== +msoCTrue) or($slide->shapes($shapeNumber)->HasTextFrame()== +msoTrue)) { my $wordGroup=$slide->shapes($shapeNumber)->TextFrame->{T +extRange}; if (defined $wordGroup) { my $text = ""; foreach my $palabre (in $wordGroup->Words) # prints ou +t every single word { $text.= lc($palabre->{Text})." "; # lc stands for l +ower case } $PPTContent{("slide".$slideNumber)}{("shape".$ +shapeNumber)} = $text; } } } } } return ($PPTName,$PPTProperties,%PPTContent); } } return (undef,undef,undef); } # structure of $PPTContent will be a hash of hashes : # first hash will contain all the slides and each slide will be a hash + itself containing all # the text areas found. # to access do this $PPTContent{slide1}{shape1}
        Heureux qui, comme Ulysse, a fait un beau voyage
        Ou comme celui-là qui conquit la Toison,
        Et puis est retourné plein d'usage et raison,
        Vivre entre ses parents le reste de son âge!

        J. du Bellay, poëte angevin