Private Function CopySelection() As String
Dim slidesSelection As SlideRange, i As Long, j As Long, k As Long, slidesNumber() As Long, pathNewPres As String, newPres As Presentation, toDelete As Boolean, myFso As Object
'récupérer la sélection
On Error Resume Next
Set slidesSelection = ActiveWindow.Selection.SlideRange
On Error GoTo ErrorManagement
If slidesSelection Is Nothing Then Exit Function
'récupérer les numéros de slides sélectionnés
ReDim slidesNumber(1 To slidesSelection.Count)
For i = 1 To slidesSelection.Count
slidesNumber(i) = slidesSelection.Item(i).SlideNumber
Next i
'trier dans l'ordre croissant les numéros de slides sélectionnés
For i = LBound(slidesNumber) To UBound(slidesNumber) - 1
For j = i + 1 To UBound(slidesNumber)
If slidesNumber(i) > slidesNumber(j) Then
k = slidesNumber(j)
slidesNumber(j) = slidesNumber(i)
slidesNumber(i) = k
End If
Next j
Next i
'créer une copie de la présentation dans le répertoire "TMP" de l'utilisateur
Set myFso = CreateObject("Scripting.FileSystemObject")
pathNewPres = Environ("TMP") & "\Copie_" & myFso.GetBaseName(ActivePresentation.Name)
' pathNewPres = pathNewPres & ".pptm" 'avec macro (.pptm)
' ActivePresentation.SaveCopyAs pathNewPres 'avec macro (.pptm)
pathNewPres = pathNewPres & ".pptx" 'sans macro (.pptx)
ActivePresentation.SaveCopyAs pathNewPres, ppSaveAsOpenXMLPresentation 'sans macro (.pptx)
Set newPres = Application.Presentations.Open(pathNewPres)
'supprimer les slides (dans la copie) qui n'étaient pas sélectionnés
For i = newPres.Slides.Count To 1 Step -1
toDelete = True
For j = LBound(slidesNumber) To UBound(slidesNumber)
If newPres.Slides(i).SlideNumber = slidesNumber(j) Then toDelete = False
Next j
If toDelete Then newPres.Slides(i).Delete
Next i
'fermer la copie
newPres.Save
newPres.Close
CopySelection = pathNewPres
Exit Function
ErrorManagement:
End Function