PDA

View Full Version : [SOLVED:] add image to one slide each with filename as text box above



saicharan
11-13-2019, 12:10 PM
i have folder with images need to make a ppt with each image in one slide and their filename as a text box above them
i have tried the below macro but images goes to the top and dont have any text box.
Hope someone can help me out, have been struggling with this:banghead:


Sub insertPics()
Dim strFolder As String ' Full path to folder
Dim strName As String
Dim oPres As Presentation
Dim osld As Slide
Dim ocust As CustomLayout
Dim x As Long
' Edit this:
strFolder = "W:\Personal Folders\Saicharan Sirangi\AA scrpits\Email attachments" 'note the last \
Set oPres = ActivePresentation
Set osld = oPres.Slides(oPres.Slides.Count)
Set ocust = osld.CustomLayout
strName = Dir$(strFolder & "*.PNG")
While strName <> ""
x = x + 1
With osld.Shapes.AddPicture(strFolder & strName, msoFalse, msoTrue, -1, -1, -1, -1)
.Line.Visible = True
.Line.ForeColor.RGB = vbWhite
End With
osld.Shapes.Title.TextFrame.TextRange = strName & x
strName = Dir()
If strName <> "" Then
Set osld = oPres.Slides.AddSlide(oPres.Slides.Count + 1, ocust)
ActiveWindow.View.GotoSlide osld.SlideIndex
End If
Wend
End Sub

John Wilson
11-19-2019, 08:55 AM
The images go to the top because you are tellingt them to!


With osld.Shapes.AddPicture(strFolder & strName, msoFalse, msoTrue, -1, -1, -1, -1)

The first two -1s set the left and top to -1 (ie the top) second pair set the height and width to their original size. You might want to try adjusting these figures

saicharan
11-19-2019, 09:51 AM
The images go to the top because you are tellingt them to!


With osld.Shapes.AddPicture(strFolder & strName, msoFalse, msoTrue, -1, -1, -1, -1)

The first two -1s set the left and top to -1 (ie the top) second pair set the height and width to their original size. You might want to try adjusting these figures

Thank you, i am pretty new at this was tryin to use script i found in this forum with minor chnages
Thanks again will fix it as you suggested .

so it has to be 0 for centre ?

John Wilson
11-20-2019, 06:10 AM
No 0 0 is actually the top and left. -1,-1 is pretty close just 1/72 inch away. PowerPoint measures in Points (72 to the inch)

The center would be ActivePresentation.PageSetUp.SlideWidth /2

The middle ActivePresentation.PageSetUp.SlideHeight /2