VBA: PowerPoint - Copy slides from one presentation to another

krehkop

Board Regular
Joined
Jul 6, 2007
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hello:

I'm a newbie re: this type of VBA but have done a lot of research (and testing) on the matter before posting here on this site. The code I've come across is too complex for me at the moment. What I would like to do is take slides from an existing presentation and paste those into a new presentation. I want to keep the same format of the presentation the slides are sourced from. Note, the two presentations have the same format/template so I'm assuming this shouldn't be an issue. The old has 10 slides and would be pasted into the new starting with slide #3. The following isn't at all what I'm wanting but wanted to show that I have successfully attempted some things that are useful:

1. Creating a new presentation, getting pictures and data ranges from an existing Excel file and formatting those.

Sub CreateNewPresentation()

Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Set ppApp = New PowerPoint.Application
ppApp.Visible = True
ppApp.Activate
Set ppPres = ppApp.Presentations.Add

Dim ExcShape As Excel.Shape
Dim WrkSht As Worksheet

Workbooks.Open "https://xxxxx365-my.sharepoint.com/...ments/PowerPoint/Xxxxxxxxx_Xxxxxx_Xxxxxx.xlsx"

'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'Slide 1
Set ppSlide = ppPres.Slides.Add(1, ppLayoutTitle)
ppSlide.Shapes(1).TextFrame.TextRange = "Sample Client Presentation"
ppSlide.Shapes(2).TextFrame.TextRange = "January - June 2022"

'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'SLIDE 2

Set ppSlide = ppPres.Slides.Add(2, ppLayoutBlank)
ppSlide.Select
Sheets(2).Select

For Each ExcShape In ActiveSheet.Shapes
If ExcShape.Type = msoPicture Then
ExcShape.Select
'Copy the Shape
ExcShape.Copy
'Paste Shape in the slide.
ppSlide.Shapes.PasteSpecial DataType:=ppPasteMetafilePicture
Set ppShape = ppSlide.Shapes(ppSlide.Shapes.Count)
ppShape.Select

'Set the dimensions of the shape
With ppApp.ActiveWindow.Selection.ShapeRange
.Left = 10
.Top = 10
.Width = 500
.Left = 10
End With

Exit For
End If
Next

Range("A4", "I14").CurrentRegion.Copy
'ppSlide.Shapes.Paste
ppSlide.Shapes.PasteSpecial DataType:=ppPasteMetafilePicture
Set ppShape = ppSlide.Shapes(ppSlide.Shapes.Count)
ppShape.Select

'Set the dimensions of the shape
With ppApp.ActiveWindow.Selection.ShapeRange
.Left = 10
.Top = 275
.Width = 500
.Left = 10
End With

'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ppApp.Activate

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The 'Working code below' used per the following location solved my issue. Thanks!


Sub Example2()
Dim objPowerPoint As New PowerPoint.Application
Dim objPresentation As Presentation
Dim i As Integer

'open the target presentation
Set objPresentation = objPowerPoint.Presentations.Open("C:\Users\john\Desktop\p123.pptx")
For i = 1 To objPresentation.Slides.Count
objPresentation.Slides.Item(i).Copy
objPowerPoint.Presentations.Item(1).Slides.Paste
objPowerPoint.Presentations.Item(1).Slides.Item(objPowerPoint.Presentations.Item(1).Slides.Count).Design = _
objPresentation.Slides.Item(i).Design
Next i
objPresentation.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,841
Messages
6,174,972
Members
452,594
Latest member
dgparryuk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top