Consulting

Results 1 to 3 of 3

Thread: Split PPT presentation and save PDFs

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Split PPT presentation and save PDFs

    Dear all,

    We have a PPT presentation which includes 131 slides. On a monthly basis we have to split the presentation into several smaller team-presentations, generate a PDF and send them via email.
    We already have a VBA in place in order to split the presentation. I am quite new to VBA and trying now that I can save the documents directly as PDFs.
    I am trying back and forth for days now but I do not get the result I am looking for.
    The perfect way would be:
    - I can run one macro and automatically all team presentations are saved as PDF in the specific team folders.
    What happens when I run the macro now is:
    - I run the macro (1 macro per team presentation), it generates and opens a new PPT with the requested slides (e.g. 22 slides) which I can then click on Save in order that it saves it in the requested folder. Additionally, it saves a PDF of the total 131 slides in the same team folder (whereas I would be looking for the PDF only containing the 22 slides).

    I am copying the VBA macro for two teams as an example, in total we have 13 teams.

    Sub ABC()
    
    ' Variable definitions
    Dim oSld As Slide
    Dim oShp As Shape
    Dim lTotalSlides As Long
    Dim Slidenumber, SlidesNeeded, Team As String
    Dim strResponse As String
    
    ' Defining the date used in nomenclature of file
    myDate = Format(Date, "_yyyy_mm_dd")
    
    'Define team name
    Team = "ABC"
    
    ' Saving paths
    ActivePresentation.ExportAsFixedFormat "O:\ABC" & myDate & ".pdf", ppFixedFormatTypePDF
    
    ' Finding the numbers of the required slides
    Slidenumber = "" ' define an empty variable for later use
    SlidesNeeded = "14,15,16,17,18,29,30,40,55,56,70,85,113,127,1 28" 'define the basic slides (dividers, etc. that are need in any presentation) -> may need adjustment from time to time
    
    lTotalSlides = ActivePresentation.Slides.Count
    
    For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
    If oShp.HasTextFrame Then
    If oShp.TextFrame.TextRange.Find(Team) Is Nothing Then
    Else: Slidenumber = oSld.Slidenumber
    SlidesNeeded = SlidesNeeded & "," & Slidenumber ' expands the SlidesNeeded with the slides that contain the team name in the title
    End If
    End If
    Next
    Next
    
    
    ' Deleting all unnecessary slides
    Dim x As Long
    Dim lSlideNumber As Long
    Dim rayKeep() As String
    Dim bKeeper As Boolean
    Dim oPres As Presentation
    
    rayKeep() = Split(SlidesNeeded, ",")
    
    Set oPres = ActivePresentation
    With oPres
    For lSlideNumber = .Slides.Count To 1 Step -1
    For x = LBound(rayKeep) To UBound(rayKeep)
    If .Slides(lSlideNumber).SlideIndex = CLng(rayKeep(x)) Then
    '.Slides(lSlideNumber).Delete
    bKeeper = True
    End If
    Next
    
    If Not bKeeper Then
    .Slides(lSlideNumber).Delete
    End If
    bKeeper = False
    
    Next
    End With
    
    End Sub
    
    Sub CEE()
    
    Dim oSld As Slide
    Dim oShp As Shape
    Dim lTotalSlides As Long
    Dim Slidenumber, SlidesNeeded, Team As String
    Dim strResponse As String
    
    myDate = Format(Date, "_yyyy_mm_dd")
    Team = "CEE"
    
    ActivePresentation.ExportAsFixedFormat "O:\CEE" & myDate & ".pdf", ppFixedFormatTypePDF
    
    Slidenumber = "" ' define an empty variable for later use
    SlidesNeeded = "14,15,16,17,18,29,30,40,55,56,70,85,113,127,1 28" 'define the basic slides (dividers, etc. that are need in any presentation) -> may need adjustment from time to time
    
    lTotalSlides = ActivePresentation.Slides.Count
    
    For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
    If oShp.HasTextFrame Then
    If oShp.TextFrame.TextRange.Find(Team) Is Nothing Then
    Else: Slidenumber = oSld.Slidenumber
    SlidesNeeded = SlidesNeeded & "," & Slidenumber ' expands the SlidesNeeded with the slides that contain the team name in the title
    End If
    End If
    Next
    Next
    
    
    ' Deleting all unnecessary slides
    Dim x As Long
    Dim lSlideNumber As Long
    Dim rayKeep() As String
    Dim bKeeper As Boolean
    Dim oPres As Presentation
    
    rayKeep() = Split(SlidesNeeded, ",")
    
    Set oPres = ActivePresentation
    With oPres
    For lSlideNumber = .Slides.Count To 1 Step -1
    For x = LBound(rayKeep) To UBound(rayKeep)
    If .Slides(lSlideNumber).SlideIndex = CLng(rayKeep(x)) Then
    '.Slides(lSlideNumber).Delete
    bKeeper = True
    End If
    Next
    
    If Not bKeeper Then
    .Slides(lSlideNumber).Delete
    End If
    bKeeper = False
    
    Next
    End With
    
    End Sub


    Any help would me much appreciated!! Already many thanks in advance!
    Best, Sonja
    Last edited by Paul_Hossler; 05-11-2020 at 10:14 AM. Reason: Added CODE tags

Posting Permissions

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