Sub insertPictures()
On Error GoTo ErrHandler
Dim sPath As String
sPath = InputBox("Enter the path of the folder with pictures")
If Right(sPath, 1) = "\" Then sPath = Left(sPath, Len(sPath) - 1)
Dim fso As Object
Dim fsoFolder As Object
Dim fsoFile As Object
Dim pptLayout As CustomLayout
Dim i As Integer
i = 1
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
Dim pptSlide As Slide
Dim pptShape As Shape
Const pixelsPerInch As Integer = 96
Set fso = CreateObject("scripting.filesystemobject")
Set fsoFolder = fso.GetFolder(sPath)
For Each fsoFile In fsoFolder.Files
i = i + 1
Set pptSlide = ActivePresentation.Slides.AddSlide(i, pptLayout)
Set pptShape = pptSlide.Shapes.AddPicture(fsoFile.Path, msoFalse, msoTrue, 0, 0)
' pptShape.ScaleHeight 0.8, msoTrue
pptShape.Top = pptShape.Top + (pixelsPerInch * 1)
pptShape.Left = (ActivePresentation.PageSetup.SlideWidth - pptShape.Width) / 2
DoEvents
Next fsoFile
Exit Sub
ErrHandler:
Resume Next
End Sub
|