Automating image insertion in powerpoint

DanR1245

New Member
Joined
May 12, 2004
Messages
27
I've done this through excel before, but never just using visual basic, so I am guessing my error revolves around setting objects correctly, etc.

This stand alone vb exe should insrt images of a set file type into a template ppt presentation.

here is my code. i am getting an "object variable or with block variable not set" and the line beginning with "oSlide.Shapes.AddPicture..." is highlighted. i think i am setting the powerpoint object and slide object, but obviously i am missing something....

' OPEN POWERPOINT TEMPLATE

Set objPPT = CreateObject(Class:="PowerPoint.Application")
objPPT.Visible = True

objPPT.Presentations.Open FileName:= _
"C:\template.ppt", ReadOnly:=False
objPPT.Visible = True
objPPT.ActiveWindow.Activate

With objPPT.FileSearch
.FileName = 1.gif
.LookIn = "c:\"
.Execute


' FIND NUMBER OF IMAGE FILES

Dim msoSortbyFileName, msoSortOrderAscending As Variant
Dim i As Integer

If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
ImageName = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If

Dim oSlide As PowerPoint.Slide
Dim msoFalse As Variant
Dim msoTrue As Variant


oSlide.Shapes.AddPicture(FileName:="C:\images\1.gif", _ LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=1, Top:=1, _ Width:=700, Height:=500).Select

End With
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,875
Messages
6,181,515
Members
453,050
Latest member
Obil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top