Link to home
Start Free TrialLog in
Avatar of blang476
blang476

asked on

How do I run a Powerpoint slide show using visual basic code?

The goal is to run a powerpoint slide show by clicking a command button on a microsoft access database form.  I have attempted this several times with different pieces of code from searching online.  If there is an easier way to do it using just a macro and no code, then I am not that well-versed.  Here are some of the samples of code I have used with several different error messages:
  Function OpenPPTFile() As Boolean

    Dim stAppName As String

    stAppName = "C:\Documents and Settings\Blang\My Documents\Powerpointz\BLangBomberz.ppt"
    Shell stAppName, vbNormalFocus

    OpenPPTFile = True

End Function

Private Sub startSlideShow()

         Dim pptObject As PowerPoint.Application
         Dim pptPres As PowerPoint.Presentation
         Set pptObject = CreateObject("PowerPoint.Application")
         pptObject.Visible = True
         Set pptPres = pptObject.Presentations.Open("C:\Documents and Settings\Blang\My Documents\Powerpointz\BLangBomberz.ppt")
         pptObject.ActivePresentation.SlideShowSettings.Run
         Set PPT = Nothing

End Sub

The error I am getting is that the property is not set for automation operations.  Any help would be appreciated.  
ASKER CERTIFIED SOLUTION
Avatar of Rick_Rickards
Rick_Rickards
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GlennaShaw
GlennaShaw

Avatar of blang476

ASKER

Perhaps my problem is in the Macro itself.  When I RunCode, what exactly am I to put in the Function Name?  I tried both startSlideShow and startSlideShow(), none of which were successful.  I am getting the same automation error as before.  I think it needs to be a Function and not a Sub, but not sure.  Thanks,
Never mind, I figured it out; it was in the macro itself.  the following code works though:
Private Sub startSlideShow()
    Dim objPPT As Object
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True
    objPPT.Presentations.Open ("C:\Documents and Settings\Blang\My Documents\Powerpointz\BLangBomberz.ppt")
    objPPT.ActivePresentation.SlideShowSettings.Run
    Set objPPT = Nothing
End Sub
You must define the code as a Function and not a Sub procedure...
Thanks
Glad you got it working.  For what it's worth the code illustrated is version independent because it relies on Late Binding.  Thus, you need not be concerned about which version of Power Point the user has, it will simply look to and run whichever version the user happens to have installed.

Rick