Log in

View Full Version : [SOLVED:] Insert PowerPoint slides keeping source formatting



fkneg1
07-19-2023, 11:43 PM
Hi,
I have an Access database with VBA that produces a PowerPoint presentation based on the chosen fields of the database. One feature of this database I would like to do is to be able to insert other PowerPoint presentations into the new presentation. I have been able to do this so far with:

.Slides.InsertFromFile _
FileName:=(rs.Fields("Extra slides 1")), Index:=0
but this does not keep the source formatting of the slides. Looking around I found that I could copy and paste the slides in instead using code like this:


Dim objPresentation As Presentation
Dim intobj As Integer


Set objPresentation = Presentations.Open("C:\123.pptx", , msoFalse) 'Error on this line

For intobj = 1 To objPresentation.Slides.Count
objPresentation.Slides.Item(intobj).Copy
Presentations.Item(1).Slides.Paste
Presentations.Item(1).Slides.Item(Presentations.Item(1).Slides.Count).Desig n = _
objPresentation.Slides.Item(intobj).Design
Next intobj
objPresentation.Close
But this is not working - I am getting error code '2147221164 Class not registered' on the line indicated and the slides are not copying in. My guess is that as the code is all running in Access to generate the presentation it doesn't know where to paste the new slides?? Any ideas?
Thanks!

fkneg1
07-20-2023, 04:40 AM
I have done a bit of tweaking and got this nearly working:

Dim objPresentation As PresentationDim objPowerPoint As New PowerPoint.Application
Dim intobj As Integer

Set objPresentation = objPowerPoint.Presentations.Open(FileName:=(rs.Fields("Extra slides 1")))


For intobj = 1 To objPresentation.Slides.Count
objPresentation.Slides.Item(intobj).Copy
objPowerPoint.Presentations.Item(1).Slides.Paste
objPowerPoint.Presentations.Item(1).Slides.Item(objPowerPoint.Presentations .Item(1).Slides.Count).Design = _
objPresentation.Slides.Item(intobj).Design

Next intobj
objPresentation.Close

BUT it pastes the slides at the end of the presentation instead of where they should go at the beginning. If I put a 1 after the 'paste' command then it pastes the slides into the correct place but without the source formatting (the source formatting is applied to the last slide of the existing PowerPoint instead). Does anyone know how I can make the pasted slides go at the beginning of the presentation and keep their source formatting?

fkneg1
07-20-2023, 12:21 PM
Solved! For anyone else looking for something similar, I found this code works:


Dim objPresentation As Presentation
Dim objPowerPoint As New PowerPoint.Application
Dim intobj As Integer


Set objPresentation = objPowerPoint.Presentations.Open(FileName:=(rs.Fields("Extra slides 1")))

For intobj = objPresentation.Slides.Count To 1 Step -1
objPresentation.Slides.Item(intobj).Copy
objPowerPoint.Presentations.Item(1).Slides.Paste 1
objPowerPoint.Presentations.Item(1).Slides.Item(1).Design = _
objPresentation.Slides.Item(intobj).Design

Next intobj
objPresentation.Close

Aussiebear
07-20-2023, 10:15 PM
Welcome to the VBAX forum, and thank you for sharing the solution for others to learn from.