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
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