Solved

How do you copy a slide from a powerpoint presentation to a new presentation

Posted on 2009-06-29
5
518 Views
Last Modified: 2012-08-13
I have multiple powerpoint templates (2007). I am trying to copy the slides from each of these templates into a new presentation. I am trying to get the syntax to copy the entire slide from one presentation to a new presentation.

Thanks for any suggestions or ideas on how to get this done.
Thanks...
Sub SlideCopy()
 

      ' Variable declarations.

      Dim SourceView, answer As Integer

      Dim SourceSlides, NumPres, x As Long
 

      ' Stores the current view of the source presentation.

      SourceView = ActiveWindow.ViewType
 

      ' Count the number of slides in source presentation.

      SourceSlides = objPresentation.Slides.Count 'objPresentatio.Slides.Count '
 

         ' Create a new presentation for the designation.

         Presentations.Add
 

        Set objPresentation2 = ActivePresentation

         

         With objPresentation2.PageSetup

            .SlideHeight = objPresentation.PageSetup.SlideHeight

            .SlideWidth = objPresentation.PageSetup.SlideWidth

        End With
 

         ' Switch to the source presentation.

         objPresentation.Windows(1).Activate
 

      ' Loop through all the slides and copy them to destination one by one.

      For x = 1 To SourceSlides

         ' Select the first slide in the presentation and copy it.
 

         objPresentation.Slides(1).Copy

         'ActiveWindow.Selection.Copy
 

         ' Switch to destination presentation.

         objPresentation2.Windows(1).Activate
 

         ' Create a new slide.

         objPresentation2.Slides.Add _

            objPresentation2.Slides.Count + 1, ppLayoutBlank
 

         ' Make sure the new presentation is slide view.

         If ActiveWindow.ViewType <> ppViewSlide Then

            ActiveWindow.ViewType = ppViewSlide

         End If
 

         ' Switch to the proper slide.

         ActiveWindow.View.GotoSlide Index:=objPresentation2.Slides.Count
 

         ' Paste the slide.

         objPresentation2.Slides.Paste    'ActiveWindow.View.Paste
 

         ' Unselect the object.

         ActiveWindow.Selection.Unselect
 

         ' Switch to source.

         objPresentation.Windows(1).Activate
 

      Next x
 

      ' Restore the current view to source.

      ActiveWindow.ViewType = SourceView
 

   End Sub

Open in new window

0
Comment
Question by:DekkaG
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:ioane
ID: 24743357
Try this, it may give you some ideas:
Sub SlideCopy()

    Dim oldP As Presentation

    Dim newP As Presentation

    Dim s As Slide

    Dim vt As Long

    

    Set oldP = Presentations(1)

    Set newP = Presentations(2)

    

    vt = newP.Windows(1).ViewType

    newP.Windows(1).ViewType = ppViewOutline

    For Each s In oldP.Slides

        s.Copy

        newP.Slides.Paste

    Next s

    newP.Windows(1).ViewType = vt

End Sub

Open in new window

0
 

Author Comment

by:DekkaG
ID: 24744255
Tramtrak,
This works great, but it isn't bringing over the formatting or slide design/background.
I adjusted your code (as below).

Any ideas?

Thanks


Sub SlideCopy2()

    Dim oldP As Presentation

    Dim newP As Presentation

    Dim s As Slide

    Dim vt As Long

    

    Set oldP = objPresentation 'Presentations(1)

    

    Presentations.Add

    Set objPresentation2 = ActivePresentation

    Set newP = objPresentation2 'Presentations(2)

    

    vt = newP.Windows(1).ViewType

    newP.Windows(1).ViewType = ppViewOutline

    For Each s In oldP.Slides

        s.Copy

        newP.Slides.Paste

    Next s

    newP.Windows(1).ViewType = vt

End Sub

Open in new window

0
 
LVL 13

Accepted Solution

by:
ioane earned 500 total points
ID: 24769927
Hi DekkaG,

How about this:
Sub SlideCopy()

    Dim oldP As Presentation

    Dim newP As Presentation

    Dim s As Slide

    Dim cl As CustomLayout

    Dim vt As Long

    

    Set oldP = Presentations("Presentation1")

    Set newP = Presentations("Presentation2")

    

    vt = newP.Windows(1).ViewType

    newP.Windows(1).ViewType = ppViewOutline

    For Each s In oldP.Slides

        s.Copy

        Set cl = s.CustomLayout

        newP.Slides.Paste

        newP.Slides(newP.Slides.Count).CustomLayout = cl

    Next s

    newP.Windows(1).ViewType = vt

End Sub

Open in new window

0
 

Author Comment

by:DekkaG
ID: 24865873
Hi Tramtrak,
Sorry for getting back to you so late. I was out of town for the past few days.

I was able to implement this solution with just a few problems:
The new template doesn't look like it is starting with a blank template and has one of the content boxes (with the icons for inserting tables, charts, smart art, etc.) on the right half of the template.

Also it looks like the object (text boxes and background) are misaligned compared to the original template. If you want I can open this up in another question.

Hopefully, these are easy issues to resolve. It is looking great so far though...
I couldn't have gotten this far without your help.

Dekka...
0
 
LVL 13

Expert Comment

by:ioane
ID: 24866381
Hi Dekka,

I'm not sure what the problem is with the extra content box, are you sure this is not on the original slide? Maybe hidden?

You may also want to check all the layout properties for the original presentation match the new presentation.

A new question might be best.

Cheers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting the Scene PowerPoint is a creative tool in the right hands but it also includes a much underutilised programming dimension. In this beginner level article, we're going to show you some of some key elements of programming PowerPoint using th…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now