I’m able to run a macro that save each slide of a presentation as a separate pdf file, and are named using a text box within that slide.
The blocker I face is when I keep source formatting while creating/pasting the new slide. When do this, the saving to pdf no longer works. It throws the below error
Run time error '-2147467259 (80004005)'
Presentation (unknown member) : The slides have selected to print longer exist.
Please make another selection.
Below is the full code.
Sub SplitSlidesIntoSeparateFilesv4()
Dim SourcePres As Presentation
Dim NewPres As Presentation
Dim SourceSlide As Slide
Dim FilePaath As String
Dim FileName As String
' Set the source presentation
Set SourcePres = ActivePresentation
' Choose the folder to save the files
FilePath = InputBox("Enter the full path where you want to save the files:", "File Path")
If FilePath = "" Then Exit Sub ' Exit if no path is provided
' The shape in the slide that contains the text to name the converted file .
shapeName = "Rectangle 35"
' Loop through each slide in the presentation
For Each SourceSlide In SourcePres.Slides
' Create a new presentation
Set NewPres = Presentations.Add
' Copy the slide
SourceSlide.Copy
' Paste the slide into the new presentation. <<< Introduction of this causes the error >>>
NewPres.Windows(1).Activate
NewPres.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
' Previous code, which works fine is below. It does not do source formatting, but saving as pdf works fine.
' NewPres.Slides.Paste
' Save the new presentation
For Each Shape In SourceSlide.Shapes
' Check if the shapes name matches the specified name
If Shape.Name = shapeName Then
FileName = FilePath & "" & "Slide_" & Shape.TextFrame.TextRange.Text & ".pdf"
NewPres.ExportAsFixedFormat _
Path:=FileName, _
FixedFormatType:=ppFixedFormatTypePDF, _
Intent:=ppFixedFormatIntentScreen, _
FrameSlides:=msoTrue, _
HandoutOrder:=ppPrintHandoutVerticalFirst, _
OutputType:=ppPrintOutputSlides, _
PrintHiddenSlides:=msoCTrue, _
PrintRange:=Nothing, _
RangeType:=ppPrintAll, _
IncludeDocProperties:=True, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
End If
Next Shape
Next SourceSlide
End Sub