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\BLan gBomberz.p pt"
Shell stAppName, vbNormalFocus
OpenPPTFile = True
End Function
Private Sub startSlideShow()
Dim pptObject As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Set pptObject = CreateObject("PowerPoint.A pplication ")
pptObject.Visible = True
Set pptPres = pptObject.Presentations.Op en("C:\Doc uments and Settings\Blang\My Documents\Powerpointz\BLan gBomberz.p pt")
pptObject.ActivePresentati on.SlideSh owSettings .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.
Function OpenPPTFile() As Boolean
Dim stAppName As String
stAppName = "C:\Documents and Settings\Blang\My Documents\Powerpointz\BLan
Shell stAppName, vbNormalFocus
OpenPPTFile = True
End Function
Private Sub startSlideShow()
Dim pptObject As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Set pptObject = CreateObject("PowerPoint.A
pptObject.Visible = True
Set pptPres = pptObject.Presentations.Op
pptObject.ActivePresentati
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,
ASKER
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.A pplication ")
objPPT.Visible = True
objPPT.Presentations.Open ("C:\Documents and Settings\Blang\My Documents\Powerpointz\BLan gBomberz.p pt")
objPPT.ActivePresentation. SlideShowS ettings.Ru n
Set objPPT = Nothing
End Sub
Private Sub startSlideShow()
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.A
objPPT.Visible = True
objPPT.Presentations.Open ("C:\Documents and Settings\Blang\My Documents\Powerpointz\BLan
objPPT.ActivePresentation.
Set objPPT = Nothing
End Sub
ASKER
You must define the code as a Function and not a Sub procedure...
Thanks
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
Rick
http://msdn2.microsoft.com/en-us/library/aa159920(office.11).aspx