Solved

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

Posted on 2007-11-17
6
2,925 Views
Last Modified: 2013-11-27
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.  
0
Comment
Question by:blang476
  • 3
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
Rick_Rickards earned 125 total points
ID: 20305500
Try this...


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

Open in new window

0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 20305520
0
 

Author Comment

by:blang476
ID: 20305635
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,
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:blang476
ID: 20305651
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
0
 

Author Closing Comment

by:blang476
ID: 31409747
You must define the code as a Function and not a Sub procedure...
Thanks
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20305772
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question