Sub ImportCharts()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
strPath = ActivePresentation.Path & "\Images\"
strFileSpec = "*.png"
strTemp = Dir(strPath & strFileSpec)
Do While strTemp <> ""
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.count 1, ppLayoutCustom)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0.45 * 72, _
Top:=0.8 * 72, _
Width:=10.1 * 72, _
Height:=6.25 * 72) '
strTemp = Dir
Loop
End Sub
In the Do while loop the ppLayoutCustom adds the first custom layout. But I want to add Content Page layout as my custom layout (Refer image).
CodePudding user response:
This thread has the same issue and this answer is mostly restating what has already been shown there.
If you know that the index of your custom layout "Content Page" will always be 3, for example, then you can go about it like this:
With ActivePresentation
.Slides.AddSlide _
Index:=.Slides.Count 1, _
pCustomLayout:=.Designs(1).SlideMaster.CustomLayouts(3)
End With
If you aren't certain that your custom layout will always have the same index, you'll need to first iterate through all of the custom layouts, find the index of the one you want, and then use the code above. Of course, you would replace the 3
with the true index of your custom layout.