Solved

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

Posted on 2007-11-17
6
2,894 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Setting the Scene Animations in PowerPoint are a great tool to convey messages when used carefuly with the content of your slides. There are plenty of animation effects and options, including a Repeat feature for individual animation effects. …
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now