helpmeinoob
04-05-2017, 08:50 AM
Hi there, first time posting and have to apologize in advance for my newbie knowledge around VBA and appreciate any help I can get from the forum.
My goal is to run an application in powerpoint that pulls all images from a folder, sizes them and pastes them into a powerpoint template I have created. I thought I found a solution, but did not realize that the Dir function capabilities are limited. I want to be able to paste the images into the template in the order they appear in the folder. I think I can sort using an Array function, but am lost on how to get this going. Here is my basic vba code that works well (except for the paste order). Any insight would be great :) Thanks so much.
Sub ImportPacket()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
strPath = "O:\Data\File\"
strFileSpec = "*.png"
strTemp = Dir(strPath & strFileSpec)
While strTemp <> ""
For Each oSld In ActivePresentation.Slides
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=30.24, _
Top:=57.6, _
Width:=645.84, _
Height:=446.4)
oPic.ZOrder msoSendToBack
strTemp = Dir
Next
Wend
End Sub
My goal is to run an application in powerpoint that pulls all images from a folder, sizes them and pastes them into a powerpoint template I have created. I thought I found a solution, but did not realize that the Dir function capabilities are limited. I want to be able to paste the images into the template in the order they appear in the folder. I think I can sort using an Array function, but am lost on how to get this going. Here is my basic vba code that works well (except for the paste order). Any insight would be great :) Thanks so much.
Sub ImportPacket()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
strPath = "O:\Data\File\"
strFileSpec = "*.png"
strTemp = Dir(strPath & strFileSpec)
While strTemp <> ""
For Each oSld In ActivePresentation.Slides
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=30.24, _
Top:=57.6, _
Width:=645.84, _
Height:=446.4)
oPic.ZOrder msoSendToBack
strTemp = Dir
Next
Wend
End Sub