Reputation: 207
I am new to the forum, and a few months new to VBA. All my coding experience is in Matlab, which so far I find much easier than VBA. I have read the forum rules, and searched for this answer high and low, but to no avail.
I am trying to paste different excel ranges into different slides of a PowerPoint. I want to modify the code below (taken in snipets from different forum answers) so that the range is pasted into the corresponding PowerPoint slide I denote, regardless of what the active slide is. I have tried "gotoslide" and that didn't work, and used ppviewnormal, but that also didn't work. This code will then be repeated for different ranges on different slides. So far the code will only work when I am on the slide it was written for, and I know it has to do with issues regarding the active slide, but cannot seem to figure out how to modify the code. Thank you in advance for your help!
' Desired Range in Excel to be copied into ppt
Sheets("Summary").Activate
Range("A5:H40").Select
' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' Denote slide where range is to be copied
Set PPSlide = PPPres.Slides(5)
' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range
PPSlide.Shapes.Paste.Select
Upvotes: 2
Views: 21460
Reputation: 71
Remove ".Select" from last line
This is shorter version of your code:
' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Copy the range as a picture
Sheets("Summary").Range("A5:H40").CopyPicture Appearance:=xlScreen, Format:=xlPicture
' Paste the range
PPPres.Slides(1).Shapes.Paste
Upvotes: 3