PDA

View Full Version : Sort User Selected Slides In Correct Order Before Pasting Into PowerPoint VBA



jayhayers
03-03-2020, 08:50 AM
I'm using this code to insert slides from another presentation easily. It works fine BUT I've noticed the copied slides come across in random order. i.e. not the same order they are in the PowerPoint file. How can I fix this please?


Dim i As Integer
Dim PPDD As String
Dim X As Long
Dim Y As Long
Dim Z As Long


With Application.FileDialog(msoFileDialogFilePicker)


.AllowMultiSelect = False
.Filters.Add "PowerPoint Files", "*.pptx; *.ppt; *.pptm; *.ppsm", 1
.Show
On Error Resume Next
PPDD = .SelectedItems.Item(1)
End With




X = InputBox("Please enter which position (slide number) you'd like the selected PowerPoint file to be inserted", "slide number", "1")
Y = InputBox("Please enter the number of the first slide you want to copy", "slide number", "1")
Z = InputBox("Please enter the number of the last slide you want to copy", "slide number", "1")


Set objPresentation = Presentations.Open(PPDD, WithWindow:=msoFalse)
For i = Y To Z
objPresentation.Slides.Item(i).Copy
Presentations.Item(1).Slides.Paste X
Presentations.Item(1).Slides.Item(Presentations.Item(1).Slides.count).Desig n = _
objPresentation.Slides.Item(i).Design
Next i
objPresentation.Close

John Wilson
03-05-2020, 05:30 AM
Your logic is faulty

Supose your are copy/pasting slides 3 to 4 as position 2

3 will paste at position 2 and then 4 will paste also at 2 - BEFORE 3.

See if reversing the loop works


For i = Z To Y Step-1