ActivePresentation.Slides.Range(Array(10, 11, 12, 13, 14, 15)).Select
Public Sub Test()
Dim min, max As Long
min = 10
max = 15
Dim tempSlide As Slide
For Each tempSlide In Application.ActivePresentation.Slides
If tempSlide.SlideNumber >= min And tempSlide.SlideNumber <= max Then
Debug.Print tempSlide.SlideNumber
tempSlide.Select
End If
Next
End Sub
Private Sub CommandButton4_Click()
Dim myInput As String
Dim savePath As String
'Name of Student
myInput = ActivePresentation.Slides(1).Shapes("TextBox2").OLEFormat.Object.Text
'Location of saved file
savePath = ActivePresentation.Path & "\" & myInput & " Antwoorden Virtueel Lab" & ".pdf"
'Select path student took
If ActivePresentation.Slides(9).Shapes("TextBox1").OLEFormat.Object.Text = "PRARDT" Then
'Change view
ActivePresentation.SlideShowWindow.View.Exit
'Prevents error
ActiveWindow.Panes(1).Activate
'Select specific slides
ActivePresentation.Slides.Range(Array(9, 11, 15)).Select
********************************************************************************
How do I use variables within the array? Mine are always in sequence but the sequence not fixed ex: 10, 11, 12, 13,14,15 or
23,24,25,26,27
I can't find anywhere that deals with that, is it possible?
*******************************************************************************************************
'save selected slides as PDF
ActivePresentation.ExportAsFixedFormat Path:=savePath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
MsgBox "file saved"
Else
MsgBox "wont work"
End If
End Sub
Option Explicit
'----------------------------------------------------------------------------------
' PowerPoint VBA Macro to export selected slides to PDF file.
'----------------------------------------------------------------------------------
' Copyright (c) 2019 BrightCarbon Ltd. All Rights Reserved.
' Source code is provided under Creative Commons Attribution License
' This means you must give credit for our original creation in the following form:
' "Includes code created by BrightCarbon Ltd. (brightcarbon.com)"
' Commons Deed @ http://creativecommons.org/licenses/by/3.0/
' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode
'----------------------------------------------------------------------------------
' Purpose : Answer to Experts Exchange question 29164957
' https://www.experts-exchange.com/questions/29164957/Create-pdf-of-slide-range-in-vba.html
' Author : Jamie Garroch
' Date : 26NOV2019
' Website : https://brightcarbon.com/
'----------------------------------------------------------------------------------
Sub SaveSelectedSlidesAsPDF()
Dim tPath As String
Dim tFilename As String
On Error GoTo errorhandler
With ActiveWindow.Selection
' Check the selection is valid
If .Type <> ppSelectionSlides Then
MsgBox "Please select one or more slides from the thumbnail pane in the normal view.", vbInformation + vbOKOnly, "Slide Selection to PDF"
Exit Sub
End If
End With
With ActivePresentation
' Create the file path and PDF filename
tPath = .Path & "\"
tFilename = Replace(.Name, ".pptm", ".pdf")
' Export the selected slides to PDF
.ExportAsFixedFormat2 Path:=tPath & tFilename, _
FixedFormatType:=ppFixedFormatTypePDF, _
Intent:=ppFixedFormatIntentPrint, _
FrameSlides:=msoFalse, _
HandoutOrder:=ppPrintHandoutHorizontalFirst, _
OutputType:=ppPrintOutputOneSlideHandouts, _
PrintHiddenSlides:=msoFalse, _
RangeType:=ppPrintSelection
MsgBox tFilename & " created here:" & vbCrLf & vbCrLf & tPath, vbInformation + vbOKOnly, "PDF Created"
End With
errorhandler:
If Err <> 0 Then MsgBox "Error " & Err & vbCrLf & Err.Description, vbCritical + vbOKOnly, "Error"
On Error GoTo 0
End Sub
Sub Auto_Select()
Dim Sld As Slide
Dim Istart As Integer
Dim Iend As Integer
'Simply loop through slide nos I could not Understand Range(Array()) part
Istart = 2 'change according to yuor need
Iend = 4 'change according to yuor need
For X = Istart To Iend
Set Sld = ActivePresentation.Slides(X)
Sld.Select
Next X
End Sub
Sub Generate_PDF_Cert()
'This function saves the last slide as a PDF file with a time stamp and the users name who completed the induction.
timestamp = Now()
Dim PR As PrintRange
Dim lngLast As Long
Dim lngStart As Long
Dim savePath As String
Dim PrintPDF As Integer
lngStart = 5
lngLast = 10
'Location of saved file
savePath = Environ("USERPROFILE") & "\Desktop\" & Format(timestamp, "yyyymmdd-hhnn") & "_" & FirstNameX & "_" & LastNameX & ".pdf"
'lngLast = ActivePresentation.Slides.count
With ActivePresentation.PrintOptions
.Ranges.ClearAll ' always do this
Set PR = .Ranges.Add(Start:=lngStart, End:=lngLast)
End With
ActivePresentation.ExportAsFixedFormat _
Path:=savePath, _
FixedFormatType:=ppFixedFormatTypePDF, _
PrintRange:=PR, _
Intent:=ppFixedFormatIntentScreen, _
FrameSlides:=msoTrue, _
RangeType:=ppPrintSlideRange
'Prompt user of file location and option to print.
PrintPDF = MsgBox("A PDF file of this certificate has been saved to: " & vbCrLf & savePath & vbCrLf & vbCrLf & "Would you like to print a copy also?", vbYesNo, "PDF File Created")
'If PrintPDF = 6 Then Call Print_Active_Slide
End Sub
If you have a PDF print driver installed (e.g. Foxit Reader), You can simply print your selection to the PDF Printer.
I use it almost daily. It works great!
BTW, did I mention that it's free?