Consulting

Results 1 to 2 of 2

Thread: Sort User Selected Slides In Correct Order Before Pasting Into PowerPoint VBA

  1. #1

    Sort User Selected Slides In Correct Order Before Pasting Into PowerPoint VBA

    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).Design = _
            objPresentation.Slides.Item(i).Design
    Next i
    objPresentation.Close

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,937
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •