Thank you for looking. Here is the code.
Option Compare Database
' Initialize variables.
Const firstSlide = 1
Dim arrSlideID() As Long
Dim pptobj As Object
Dim slideindex As Long, slidecount As Long
Sub ErrHandler()
Dim strError As String
Dim errObj As Error
strError = " "
If DBEngine.Errors.Count > 0 Then
For Each errObj In DBEngine.Errors
strError = strError & Format$(errObj.Number)
strError = strError & " : " & errObj.Description
strError = strError & " (" & errObj.Source & ") . "
strError = strError & Chr$(13) & Chr$(10)
Next
MsgBox strError
Else
MsgBox "Error: " & Err & " " & Error
End If
End Sub
Private Sub Form_Load()
On Error GoTo Form_Load_Error
Dim i As Integer
Dim holder As Long, present As Object
' Start Powerpoint and open an existing presentation.
holder = Shell("c:\Program Files\Microsoft Office\Office\Powerpnt.exe")
Set pptobj = CreateObject("PowerPoint.Application")
Set present = pptobj.Presentations.Open _
("C:\Users\rmclean.NDCBF.000\Desktop\2009 Easter Message.ppt")
' Determine the number of slides in the presentation.
slidecount = present.Slides.Count
' Fill an array with all Slide IDs.
ReDim arrSlideID(1 To slidecount)
For i = 1 To slidecount
arrSlideID(i) = present.Slides(i).SlideID
Next i
' Close the presentation.
pptobj.Presentations _
("C:\Users\rmclean.NDCBF.000\Desktop\2009 Easter Message.ppt").Close
Set present = Nothing
Exit Sub
Form_Load_Error:
ErrHandler
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Error
' Close Powerpoint.
pptobj.Quit
Exit Sub
Form_Unload_Error:
ErrHandler
Exit Sub
End Sub
Private Sub frstSlide_Click()
On Error GoTo frstSlide_Click_Error
' Set SourceItem property to first slide and create a link.
With pptFrame
.SourceItem = arrSlideID(firstSlide)
.Action = acOLECreateLink
End With
slideindex = firstSlide
Exit Sub
frstSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
Private Sub insertShow_Click()
On Error GoTo insertShow_Click_Error
' Make object frame visible and enable "navigation" buttons.
pptFrame.Visible = True
frstSlide.Enabled = True
lastSlide.Enabled = True
nextSlide.Enabled = True
previousSlide.Enabled = True
' Specify OLE Class, Type, SourceDoc, SourceItem and other
' properties.
With pptFrame
.Class = "Microsoft Powerpoint Slide"
.OLETypeAllowed = acOLELinked
.SourceDoc = "C:\Users\rmclean.NDCBF.000\Desktop\2009 Easter Message.ppt"
.SourceItem = arrSlideID(firstSlide)
.Action = acOLECreateLink
End With
' Set slide index to the first slide.
slideindex = firstSlide
frstSlide.SetFocus
insertShow.Enabled = False
Exit Sub
insertShow_Click_Error:
ErrHandler
Exit Sub
End Sub
End Sub
Private Sub lastSlide_Click()
On Error GoTo lastSlide_Click_Error
' Set SourceItem property to previous slide and create a link.
With pptFrame
.SourceItem = arrSlideID(slidecount)
.Action = acOLECreateLink
End With
slideindex = slidecount
Exit Sub
lastSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
Private Sub nextSlide_Click()
On Error GoTo nextSlide_Click_Error
' Determine if current slide is last slide.
If slideindex < slidecount Then
slideindex = slideindex + 1
' Set SourceItem property to next slide and create a link.
With pptFrame
.SourceItem = arrSlideID(slideindex)
.Action = acOLECreateLink
End With
Else
MsgBox "This is the last slide."
End If
Exit Sub
nextSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
Private Sub previousSlide_Click()
On Error GoTo previousSlide_Click_Error
' Determine if current slide is first slide.
If slideindex > firstSlide Then
slideindex = slideindex - 1
' Set SourceItem property to previous slide and create a link.
With pptFrame
.SourceItem = arrSlideID(slideindex)
.Action = acOLECreateLink
End With
Else
MsgBox "This is the first slide."
End If
Exit Sub
previousSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
I get the following errors when open form and hit the 'Get Presentation' button.
Error 9: subscript out of range
Error 91: Object variable or with block variable not set
Error: 53 File not found