Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add an image to a PowerPoint file

Tags:

powerpoint

vba

Is there a way to programmatically add an image to a PowerPoint file?

  1. Create the file, open the file
  2. Add the image
  3. Close the file

I need to do this to about 1000 PowerPoint files.

like image 275
Alex Gordon Avatar asked Oct 15 '25 14:10

Alex Gordon


1 Answers

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
like image 186
variant Avatar answered Oct 17 '25 04:10

variant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!