Reputation: 23
I have set up a macro which saves some charts from an Excel spreadsheet as pictures (as part of a larger procedure), and need some code to paste these pictures, one per slide, into a slideshow.
Currently, I have successfully opened up a powerpoint presentation with 4 blank slides, and have not even managed to successfully import 1 picture.
I have been using methods like shape.addpicture("C:\Users\restofpathname"), but have not managed to get them to work
Upvotes: 0
Views: 6010
Reputation: 23
Here is the code which allowed me to put a picture in powerpoint, from excel. The code below works, and this link is also useful
Dim applPP As PowerPoint.Application, prsntPP As PowerPoint.Presentation, TitlePage As PowerPoint.Slide
Set applPP = New PowerPoint.Application
applPP.Visible = True
Set prsntPP = applPP.Presentations.Add
Set TitlePage = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitle)
prsntPP.SaveAs ("C:\Users\...")
Dim oSlide As PowerPoint.Slide
Dim oPicture As PowerPoint.Shape
Set oSlide = prsntPP.Slides(1)
Set oPicture = oSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", _
msoFalse, msoTrue, 1, 2, 3, 4)
oPicture.ScaleHeight 0.9, msoTrue
oPicture.ScaleWidth 0.9, msoTrue
With prsntPP.PageSetup
oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
End With
Upvotes: 0