Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Powerpoint OLE

by rchiav (Deacon)
on Sep 08, 2001 at 19:58 UTC ( #111176=note: print w/replies, xml ) Need Help??

in reply to Powerpoint OLE

Armed with Win32::OLE and the Powerpoint object model you should have enough to do what you want to do. The tougher part is weeding through the information there. Also, if you have the Activestate installation of Perl, you can find an OLE browser in the help files.

Hope this helps..

Replies are listed 'Best First'.
Re: Re: Powerpoint OLE
by smithwt (Initiate) on Sep 08, 2001 at 21:03 UTC

    Thanks for the links. I still am having problems getting off the dime. I'm running the following code which opens Powerpoint, but goes no further:

    use Win32::OLE; use Cwd; use File::Copy; $cwd = cwd(); $input = 'input.xls'; $input_file = "$cwd\\Metrics_Data.txt"; copy ("Template1.xls", "$input"); print "Template file is: $template1\n\n"; print "Input file is: $input\n\n"; open INPUT_FILE, $input || die "No file\n"; $PptApp = Win32::OLE->new ('Powerpoint.Application'); $PptApp->{Visible} = 1; $PpptApp = Presentations(Presentation1)->Open("$input"), ReadOnly ->Tr +ue;
    I made the following ppt macro and am trying to convert it to Perl:
    Sub Open_Slide() ' ' Macro recorded 9/8/2001 by William T. Smith ' Presentations.Add WithWindow:=msoTrue ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(I +ndex:=1, Layout:=ppLayoutBlank).SlideIndex End Sub
    If you have any sample code to get me over the initial hump, I'll be flying...


      OK.. don't take this too harshly, because it's all meant in the spirit of learning. The problem here is that you have quite a bit to learn about OLE with Perl in general. There's various things you're doing that just won't work.

      First, you need to read the information about the OLE objects for powerpoint. I've never done any OLE Automation with Powerpoint, but this is what I've gathered..

      Let's take a look at the following line..

      $PpptApp = Presentations(Presentation1)->Open("$input"), ReadOnly ->Tr +ue;
      The first thing here is that you're not specifying where "Presentations(..)->Open is. Presentations is a member of PptApp. You have to remember that what you're doing is creating an instance of powerpoint here. When you write a macro, you're already in powerpoint so you don't have to tell it that it's using itself. OLE gives you the ability to use functions that other apps export outside themselves. So so for our purposes, we'll change this to
      $PpptApp = $PptApp->Presentations(Presentation1)->Open("$input"), Read +Only ->True;
      This still won't work though.
      Now look at this which describes the Presentation collection.
      In that, you'll see..

      Use Presentations(index), where index is the presentation's name or index number, to return a single Presentation object.

      This is referring to the presentations that are already in the collection. Currently, you have no presentations, so you can't refrence one. What you want to do though is add one. Actually you want to open an existing one and add it to the collection. So that leads us to this, which describes the Open functionality. You'll see..

      expression.Open(FileName, ReadOnly, Untitled, WithWindow)
      expression Required. An expression that returns a Presentations collection.

      OK.. so we also know that Presentations returns a Presentation Collection. So that would now make out line..

      $PpptApp = $PptApp->Presentations->Open("$input"), ReadOnly ->True;
      Now.. this will actually open the file.. but it's still not correct. If you look back at the information on Open, you'll see that it takes 4 arguments. The last 3 are optional. Respectivly they are "Readonly", "Untitled" and "WithWindow". In Perl, there's no True and False keywords.. but 0 (false) and 1(true) will suffice. So we now change the line to..
      my $PpptApp = $PptApp->Presentations->Open("$input", 1);
      and it does what we want it to do.

      That should also help you figure out how you have to format other things to get them to work correctly.

      Hope this helps..

Re: Re: Powerpoint OLE
by smithwt (Initiate) on Sep 08, 2001 at 21:35 UTC
    Rich, I noticed that I sent you the wrong snippit. The "xls" extensions, of course, will not work. I cleaned up my stupitiy, but still can't get Powerpoint to launch on a given ppt file. Do you (or anyone else) have example code I could review/learn from? Tnx! Bill

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://111176]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-09-27 14:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found