Is there a way to programmatically add an image to a PowerPoint file?
I need to do this to about 1000 PowerPoint files.
You might want to look into using FileSystemObject here to run Otaku's code for each file in a specific directory
Dim objFSO As Object, objFile As Object, strPath As String, p as Presentation
strPath = "C:\Wherever\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
For Each objFile In objFSO.GetFolder(strPath).Files
If InStr(1, UCase(objFile.Name), ".JPG") + _
InStr(1, UCase(objFile.Name), ".GIF") + _
InStr(1, UCase(objFile.Name), ".PNG") + _
InStr(1, UCase(objFile.Name), ".BMP") > 0 Then
'# use Otaku's code above to add a presentation, the image, then close
Set p = Presentations.Add(msoFalse)
With p
.Slides.Add Index:=1, Layout:=ppLayoutBlank
.Slides(1).Shapes.AddPicture FileName:=strPath & objFile.Name, _
LinktoFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=10, Top:=10
.SaveAs strPath & Left(objFile.Name, InStr(1, objFile.Name, ".") - 1)
.Close
End With
Set p = Nothing
End If
Next
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With