I have created some code in Excel VBA to create a PowerPoint presentation 1 slide for each row of Excel, and populate in a specific text box in PowerPoint.
I now want to add
This is how you add pictures in currently open PPT Picture PlaceHolders
using Excel.
We used Early Binding
adding the Microsoft PowerPoint 14.0 Object Library
reference.
Edit1: Adding DoEvents and some explanation
Sub ImportPictureInPlaceHolderFromExcel()
Dim oPPt As PowerPoint.Application
Dim oPPtSlide As PowerPoint.Slide
Dim oPPtShp As PowerPoint.Shape
'~~> Get hold of PPt instance meaning your currently open PPT presentation
Set oPPt = GetObject(, "Powerpoint.Application")
'~~> Reference the first slide which should contain picture placeholders
Set oPPtSlide = oPPt.ActivePresentation.Slides(1)
'~~> Now check each shape in slide
For Each oPPtShp In oPPtSlide.Shapes
'~~> You only need to work on Picture place holders
If oPPtShp.PlaceholderFormat.Type = ppPlaceholderPicture Then
With oPPtShp
'~~> Now add the Picture
'~~> For this example, picture path is in Cell A1
oPPtSlide.Shapes.AddPicture Range("A1").Value, msoFalse, msoTrue, _
.Left, .Top, .Width, .Height
'~~> Insert DoEvents here specially for big files, or network files
'~~> DoEvents halts macro momentarily until the
'~~> system finishes what it's doing which is loading the picture file
DoEvents
End With
End If
Next
Set oPPtSlide = Nothing
Set oPPt = Nothing
End Sub
To sum-up:
1. We get hold of PPT application
2. We get hold of the slide and the shapes within the slide
3. Now we choose shapes which are ppPlaceholderPicture
type only
4. We use the Shape Object's
(ppPlaceholderPicture type) .Top, .Left, .Width and .Height
property as argument for Shapes Collection's .AddPicture
method.
And there you go, you've added a picture in your PPT Picture Placeholder.
Hope this is what you need.