'********************
'* §lamKeys §oftware 2000® (mailto: slamkeys@ev1.net)
'*
'* @CREATED : 11/18/2002 1:26:09 AM by VBSlammer
'* @PARAMS : strPPT - Full path to powerpoint file
'* strPicPath - Full path to picture file
'* intSlideNo - valid slide index
'* @RETURNS : True if successful, False otherwise
'* @NOTES :
'* @MODIFIED :
'********************
Public Function AddPowerPointPicture(ByVal strPPT As String, _
ByVal strPicPath As String, _
Optional ByVal intSlideNo As Integer = 1) As Boolean
On Error GoTo ErrHandler
Dim ppt As PowerPoint.Application
Dim pres As PowerPoint.Presentation
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim blnValidPPT As Boolean
Dim strNewName As String
Dim intTotal As Integer
Dim intSlash As Integer
Dim intDot As Integer
' check image first - abort if not exists
If Dir(strPicPath) = "" Then
MsgBox strPicPath & " does not exist, aborting operation.", vbInformation
GoTo ExitHere
End If
' Verify presentation file path
If Len(strPPT) = 0 Then
blnValidPPT = False
ElseIf Dir(strPPT) = "" Then
blnValidPPT = False
Else
blnValidPPT = True
End If
' Create the app.
Set ppt = New PowerPoint.Application
' set reference to presentation
If Not blnValidPPT Then
' Add new presentation.
Set pres = ppt.Presentations.Add(False)
' Add a slide.
Set sld = pres.Slides.Add(1, ppLayoutBlank)
Else
' Open the presentation.
Set pres = ppt.Presentations.Open(strPPT, False, , False)
' Verify slide number
intTotal = pres.Slides.Count
If (intSlideNo < intTotal) Or (intSlideNo > intTotal) Then
intSlideNo = 1
End If
' reference the slide
Set sld = pres.Slides(intSlideNo)
End If
' add the picture
Set shp = sld.Shapes.AddPicture(strPicPath, False, True, 20, 20, 100, 200)
' Get image name from path
intSlash = InStrRev(strPicPath, "\")
strNewName = Right(strPicPath, Len(strPicPath) - intSlash)
intDot = InStr(strNewName, ".")
strNewName = Left(strNewName, intDot - 1)
' Save - you could modify the path.
pres.SaveAs "C:\" & strNewName & ".ppt"
' close the presentation.
pres.Close
' shut down the app.
ppt.Quit
' Success
AddPowerPointPicture = True
ExitHere:
On Error Resume Next
' dereference
Set shp = Nothing
Set sld = Nothing
Set pres = Nothing
Set ppt = Nothing
Exit Function
ErrHandler:
Debug.Print Err & " - " & Err.Description
Resume ExitHere
End Function