Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically merge powerpoint presentations

Status
Not open for further replies.

Gill1978

Programmer
Jun 12, 2001
277
GB
Hi all,

I'm trying to figure out a way in which I can get a powerpoint macro to automatically (based on file selections made on a .NET front end), merge the selected filed into a new powerpoint presentation.

However, since I've never worked with VBA - have no idea whether this is possible or where to start with it.

I've tried the easy way but using the record macro function and that doesn't do allot ...

Can someone help .... give me a place to start ????

Any help would be much appreciated ..

Thanks

Julie

 
What did the macro recorder give you?
I have never worked with macros in PowerPoint but I imagine the object model includes a slides collection. So you would have something like
Code:
dim slideList as new Collection
Then you might have something like
Code:
for each ppFile in <your list of files>
next
Nested inside that, you would need to open the file and add each slide to the slideList collection
Code:
<however PP-VBA opens a file>
for each ppSlide in <thisProject.slides>
  slideList.add(ppSlide)
next

Again, I don't know the syntax but there should be some analogous code in whatever the macro recorder produced.

_________________
Bob Rashkin
 
Hi,

This is what recorder gave me:

Code:
Sub Macro5()
'
' Macro recorded 08/05/2007 by Any Authorised User
'
    Presentations.Add WithWindow:=msoTrue
    ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutBlank).SlideIndex
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 2").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject(Left:=180, Top:=135, Width:=360, Height:=270, ClassName:="PowerPoint.Show.8", Link:=msoFalse).Select
    ActiveWindow.Selection.ShapeRange.OLEFormat.Activate
    With ActiveWindow.Selection.ShapeRange
        .Left = 183.5
        .Top = 137.875
        .Width = 353
        .Height = 264.25
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutBlank).SlideIndex
End Sub

In what form do I need to pass the list of files?? Do they have to be comma delimited?

Thanks

Julie
 
It's even easier than I thought (assuming I understand what you're trying to do. Let's say you have an empty presentation file where you want to merge all the slides from several other presentations. We'll call that merged.ppt. Now lets say you have, oh, 5 other presentations you want to merge; we'll call them p1.ppt, p2.ppt, p3.ppt, p4.ppt, p5.ppt. First we'll put those file names in a collection and then we'll add their slides to merged's slides. So, merged.ppt is open and it includes this code:
Code:
dim fnames as new collection
fnames.add "p1.ppt"
fnames.add "p2.ppt"
fnames.add "p3.ppt"
fnames.add "p4.ppt"
fnames.add "p5.ppt"
for each fnam in fnames
  activepresentation.slides.insertfromfile(fnam,activepresentation.slides.count)
next


_________________
Bob Rashkin
 
Sorry. I think you have to capture the return from insertfromfile, at least you do in the immediate window. So activepresentation.slides.insertfromfile(fnam,activepresentation.slides.count) would be nslides = activepresentation.slides.insertfromfile(fnam,activepresentation.slides.count)

_________________
Bob Rashkin
 
Hi,

So to open a new file I use the following:

Code:
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide

    ' Create instance of PowerPoint
    Set PPApp = CreateObject("Powerpoint.Application")

    ' Create a presentation
    Set PPPres = PPApp.Presentations.Add

To merge files I use:

Code:
Dim nSlides As Integer
Dim fnames As New Collection
fnames.Add "p1.ppt"
fnames.Add "p2.ppt"
fnames.Add "p3.ppt"
fnames.Add "p4.ppt"
fnames.Add "p5.ppt"
For Each fnam In fnames
  nSlides = ActivePresentation.Slides.InsertFromFile(fnam, ActivePresentation.Slides.Count)
Next

How do I make sure that the above code is merging the files into the PPPres file?

Thanks

J
 
Since VBA has to be part of an application, I would put the macro in a module in PPPres. Then I would open that file by clicking it. It is then, by definition, ActivePresentation.

_________________
Bob Rashkin
 
Hi,

... this has to run directly from a .NET webpage ... and the PPPres file would be created on the fly when the button (macro) is run.

Is this possible ?

Thanks for all the help

J
 
I suppose so. Just to be sure (although I think that, since PPPres is the only presentation open it has to be active) you can add PPPres.activate.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top