Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2020, 02:05 AM
sonj sonj is offline VBA - split PPT presentation and save PDFs Windows 7 64bit VBA - split PPT presentation and save PDFs Office 2010
Novice
VBA - split PPT presentation and save PDFs
 
Join Date: Feb 2020
Posts: 1
sonj is on a distinguished road
Question VBA - 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 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
Reply With Quote
Reply

Tags
pdf, ppt, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - split PPT presentation and save PDFs Compatibility of 2 macros in mail merge: Delete table rows + save individual PDFs Btop Word VBA 26 03-07-2018 01:45 PM
Word VBA - Split Document By Headings - Save File Name As Heading Name jc491 Word VBA 9 11-16-2015 08:52 PM
MS Save as PDF Add-in Saved PDFs have spaces in the middle of words WaltR Word 32 10-03-2015 01:16 PM
Split one Word Document into Multiple PDFs VieraOfficeUser Word 3 07-30-2014 10:58 PM
VBA - split PPT presentation and save PDFs Save as PDF - How to add extra functionality to split by page break amlong Word VBA 7 02-22-2013 11:34 PM


All times are GMT -7. The time now is 04:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft