Consulting

Results 1 to 2 of 2

Thread: VBA Add slide to the end of the presentation

  1. #1

    VBA Add slide to the end of the presentation

    currently tis code does paste sth from excel into powerpoint. Unfortunately it creates a slides in the beginning of the presentation. How do I change the code, that it adds a slide and therefore copies the range from excel to a new slide which is placed after the current slide?

    Sub copyRangeToPresentation()
    ' Open New PowerPoint Instance
    Set pptApp = CreateObject("PowerPoint.Application")
     With pptApp
        ' Activate exsting presentation
        Set ppt = .ActivePresentation
        ' Add A Blank Slide
        Set newSlide = ppt.Slides.Add(1, 12) ' ppLayoutBlank = 12
        ' Copy Range from Active Sheet in Excel
        ActiveSheet.Range("A1:E10").Copy
        ' Paste to Powerpoint as an Image
        newSlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
        ' Switch to PowerPoint
        .Activate
    End With
    End Sub
    Last edited by Aussiebear; 04-16-2023 at 04:04 PM. Reason: reduced the whitespace

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    A little late to the message, but add one to the slides count.

    Sub copyRangeToPresentation()
    ' Open New PowerPoint Instance
    Dim SldCount as long 
    Set pptApp = CreateObject("PowerPoint.Application")
     With pptApp
        ' Activate exsting presentation
        Set ppt = .ActivePresentation
        SldCount =  ppt.Slides.Count
        ' Add A Blank Slide
        Set newSlide = ppt.Slides.Add(SldCount + 1, 12) ' ppLayoutBlank = 12
        ' Copy Range from Active Sheet in Excel
        ActiveSheet.Range("A1:E10").Copy
        ' Paste to Powerpoint as an Image
        newSlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
        ' Switch to PowerPoint
        .Activate
    End With
     End Sub
    [/QUOTE]
    Last edited by Aussiebear; 04-16-2023 at 04:05 PM. Reason: reduced the whitespace

    David


Posting Permissions

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