0% found this document useful (0 votes)
27 views3 pages

Picture Placing Macro For

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Picture Placing Macro For

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Option Explicit

Public Function GetLayout( _


LayoutName As String, _
Optional ParentPresentation As Presentation = Nothing) As CustomLayout

If ParentPresentation Is Nothing Then


Set ParentPresentation = ActivePresentation
End If

Dim oLayout As CustomLayout


For Each oLayout In ParentPresentation.SlideMaster.CustomLayouts
If oLayout.Name = LayoutName Then
Set GetLayout = oLayout
Exit For
End If
Next
End Function
Sub InsertImages()
'Insert all image files from the same level folder
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim txt As PowerPoint.Shape
Dim tmp As PowerPoint.PpViewType
Dim fol As Object, f As Object
Dim tName As String
Dim oSlide As Slide
Dim oShape As Shape
Dim pptSlide As Slide
Dim pptLayout As CustomLayout

'Store open presentation in prs


'Set prs = ActivePresentation

'Store open presentation in pptlayout


Set pptLayout = ActivePresentation.Slides(1).CustomLayout

'Cancel if slide show mode


If SlideShowWindows.Count > 0 Then pptLayout = ActivePresentation

With ActiveWindow
tmp = .ViewType 'Remember window display mode
.ViewType = ppViewSlide
End With

'Get the path of the folder where this ppt file are.

Dim sFolder As String


' Open the select folder prompt
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
sFolder = .SelectedItems(1)
End If
End With

If sFolder <> "" Then ' if a file was chosen


End If

'Processing files in the folders


With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(sFolder) Then GoTo Fin

For Each f In .GetFolder(sFolder).Files


'Process only JPEG files
Select Case LCase(.GetExtensionName(f.Path))
Case "jpg", "jpeg"
'Add slids
Set pptSlide = ActivePresentation.Slides.AddSlide(2, pptLayout)
pptSlide.Select
'Insert image
Set shp = pptSlide.Shapes.AddPicture(FileName:=f.Path, LinkToFile:=False,
SaveWithDocument:=True, Left:=0, Top:=0)
With shp
.LockAspectRatio = True 'Fix the aspect ratio

'Fit inserted image to slide size


If .Width > .Height Then
'.Width = pptSlide.PageSetup.SlideWidth
.Width = pptSlide.CustomLayout.Width
Else
.Height = pptSlide.CustomLayout.Height
End If
.Select

'Resize image
.Width = .Width * 0.85
.Height = .Height * 0.85
End With

'Center image on slide


With ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
tName = f.Name
'Change slide title to file name
'oShape.Shapes(1).TextFrame.TextRange.Text = Left(f.Name, InStrRev(f.Name, ".") -
1)
'pptSlide.CustomLayout.Name = tName

pptSlide.Shapes(1).TextFrame.TextRange.Text = Left(f.Name, InStrRev(f.Name, ".") -


1)
End Select
Next
End With
For Each pptSlide In ActivePresentation.Slides
For Each oShape In pptSlide.Shapes
If oShape.HasTextFrame Then
With oShape
.Height = 50
.Width = 700
.Left = 0
.Top = 0
.TextFrame.HorizontalAnchor = msoAnchorCenter
.TextFrame.TextRange.Characters.Font.Name = "Arial"
.TextFrame.TextRange.Characters.Font.Bold = msoTrue
.TextFrame.TextRange.Characters.Font.Size = 30
.TextFrame.TextRange.Characters.Font.Underline = msoTrue
.TextFrame.TextRange.ChangeCase ppCaseUpper
End With
End If
Next oShape
Next pptSlide
Fin:
ActiveWindow.ViewType = tmp 'Restore window display mode
End Sub

You might also like