PDA

View Full Version : VBA Add slide to the end of the presentation



o0omax
08-03-2021, 02:42 AM
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

Tinbendr
04-10-2023, 06:52 AM
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]