Consulting

Results 1 to 4 of 4

Thread: Insert PowerPoint slides keeping source formatting

  1. #1
    VBAX Regular
    Joined
    Oct 2013
    Posts
    17
    Location

    Insert PowerPoint slides keeping source formatting

    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).Design = _
            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!
    Last edited by fkneg1; 07-20-2023 at 12:06 AM.

  2. #2
    VBAX Regular
    Joined
    Oct 2013
    Posts
    17
    Location
    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?

  3. #3
    VBAX Regular
    Joined
    Oct 2013
    Posts
    17
    Location
    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

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Welcome to the VBAX forum, and thank you for sharing the solution for others to learn from.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •