VB Script to open any Powerpoint extension in an automated way

' Startpptx.vbs
' VBScript program to Launch PowerPoint documents from CD/DVD.
' To run this: Add AutoRun.inf, Powerpoint document and VB executable
'
' ----------------------------------------------------------------------
' Copyright (c) 2011 Melvin Jackson Jr.
' Version 1.0 - Dec 10, 2011
'
'PPTX Script
Dim objshell
Set objShell = CreateObject("Wscript.Shell")
wscript.sleep 60000
objShell.Run "powerpnt /s  C:\ExecPPT\Win7-Managed Desktop Environment- Developers_5.0.pptx"
MJSNAsked:
Who is Participating?
 
markdmacCommented:
I was more looking to understand what is the industry that would use this. Having been an instructor and a vendor, in neither case would I want this to work as you describe.  I am happy to further tweak my code but need to better understand how and where this would be used.  Right away I would think it would be better to have a config file that would list the order of presentations to be shown.
0
 
Daz_1234Commented:
Your run line needs tweaking to take care of spaces in the path.  Here you go:

objShell.Run "powerpnt /s  ""C:\ExecPPT\Win7-Managed Desktop Environment- Developers_5.0.pptx""", 1, False

Open in new window


... and I take it you are deliberately waiting 1 minute (60,000 milliseconds) until executing?

Hope this helps,
Daz.
0
 
markdmacCommented:
Instead of running with the shell, why not use the PowerPoint application itself?

On Error Resume Next

Presentation = "C:\Temp\Hello There.pptx"

Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True

Set objPresentation = objPPT.Presentations.Open(Presentation)

objPresentation.SlideShowSettings.StartingSlide = 1
objPresentation.SlideShowSettings.EndingSlide = objPresentation.Slides.Count

Set objSlideShow = objPresentation.SlideShowSettings.Run.View
objPresentation.Saved = True

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
MJSNAuthor Commented:
OK both sound great but what I was looking for is to have this VB script launch any Powerpoint 2010 presentation regardless of the naming convention.  As long as it is a pptx extension launch the presentation...
0
 
Daz_1234Commented:
This script will open the first .ppt or .pptx file it finds in the same folder as itself, regardless of its name.

'# D.Collins - 09:34 23/12/2011
'# Open the first ppt / pptx file found in the same folder as this script

strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

Set oFolder = fso.GetFolder(strCurrDir)
Set oFiles = oFolder.Files

blFoundOne = False
For Each oFile In oFiles
    If Right(oFile.Name, 4) = ".ppt" Or Right(oFile.Name, 5) = ".pptx" Then
        wshShell.Run "powerpnt /s  """ & oFile.Path & """", 1, False
        blFoundOne = True
    End If
Next

If Not blFoundOne Then
    MsgBox "No PowerPoint presentations found in script folder: " & strCurrDir, vbSystemModal + vbExclamation, "No ppt / pptx found"
End If

Open in new window


Happy Christmas,
Daz.
0
 
Daz_1234Commented:
Slight change to the above:  As it was if there was more than one ppt / ppts it would have tried to open them all, instead of just the first one found.
'# D.Collins - 09:47 23/12/2011
'# Open the first ppt / pptx file found in the same folder as this script

strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

Set oFolder = fso.GetFolder(strCurrDir)
Set oFiles = oFolder.Files

blFoundOne = False
For Each oFile In oFiles
    If Right(oFile.Name, 4) = ".ppt" Or Right(oFile.Name, 5) = ".pptx" Then
        wshShell.Run "powerpnt /s  """ & oFile.Path & """", 1, False
        blFoundOne = True
        Exit For
    End If
Next

If Not blFoundOne Then
    MsgBox "No PowerPoint presentations found in script folder: " & strCurrDir, vbSystemModal + vbExclamation, "No ppt / pptx found"
End If

Open in new window

Happy Christmas,
Daz.
0
 
Daz_1234Commented:
Crikey, it must be Christmas or something.  Another change:  As it was the extension had to be in lower case, in this one it doesn't matter what case it is, e.g. pptx / PPTX / pPtX  etc will all work:
'# D.Collins - 09:47 23/12/2011
'# Open the first ppt / pptx file found in the same folder as this script

strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

Set oFolder = fso.GetFolder(strCurrDir)
Set oFiles = oFolder.Files

blFoundOne = False
For Each oFile In oFiles
    If LCase(Right(oFile.Name, 4)) = ".ppt" Or LCase(Right(oFile.Name, 5)) = ".pptx" Then
        wshShell.Run "powerpnt /s  """ & oFile.Path & """", 1, False
        blFoundOne = True
        Exit For
    End If
Next

If Not blFoundOne Then
    MsgBox "No PowerPoint presentations found in script folder: " & strCurrDir, vbSystemModal + vbExclamation, "No ppt / pptx found"
End If

Open in new window

Happy Christmas,
Daz.
0
 
markdmacCommented:
I would still stick with using the built in automation for PowerPoint since it offers a number of additional choices should you choose to use them like changing the advance time for slides.  I would also recommend using the File Type property to find your PowerPoint files rather than enumerating the extension only because it is a faster coding method.

The below version will launch the first PowerPoint slideshow it finds.  I opted not to give an error message if no file is found thinking that you would not want an error message popping up while doing a presentation.

Hope this helps,

Mark
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = objFSO.GetFolder(objFSO.GetParentFolderName(WScript.ScriptFullName))

For Each oFile In oFolder.Files
	If InStr(oFile.Type, "PowerPoint") > 0 Then
		Presentation = oFile.Path
		Set objPPT = CreateObject("PowerPoint.Application")
		objPPT.Visible = True
		
		Set objPresentation = objPPT.Presentations.Open(Presentation)
		
		objPresentation.SlideShowSettings.StartingSlide = 1
		objPresentation.SlideShowSettings.EndingSlide = objPresentation.Slides.Count
		
		Set objSlideShow = objPresentation.SlideShowSettings.Run.View
		objPresentation.Saved = True
		Exit For
	End If
Next

Open in new window

0
 
MJSNAuthor Commented:
Hello DAz 1234, would it be wise to add pps to the logic as well
0
 
markdmacCommented:
Mjsn, have you tried my code? No file version is needed if you use file type.
0
 
MJSNAuthor Commented:
I just tried it and it works well.....  Do you think it is wise to have several PowerPoint documents in a folder..  This way once the first presentation is over the next would start.  Or should I only except one file in the folder to be launched.
0
 
markdmacCommented:
Well, I don't know what your need is.  The script I provided can easily be modified to move on to the next file if that is what you need.

What are you going to use this for?  Will this be for a trade show demo?  Will it be an unmanned demo?  Or will a presenter be using this?
0
 
MJSNAuthor Commented:
Preseneter will be using this....  Currently the need is for a one to one...  However I invision the client requesting for the script to launch the next PPTX, PPS and PPT file on the CD or fileshare
0
 
Daz_1234Commented:
Hi,

The adapted script from my earlier method expands on what you've said and I made it much easier to add extensions if you wish.  markdmac is right when he says that his method does not require the extensions to be specified, but I've retained my original method here to give you the alternative.

I should add that neither this method, nor the PowerPoint automation method will work unless the full PowerPoint is installed.  the PowerPoint viewer does not have the automation object and is not called powerpnt.exe.

I have indicated in two places: one is where you can remove a line so that it will show each presentation in turn one after the other.  I don't know what order it will choose though.  The other is where you can remove the message box (or adapt it) if no presentation is found.

Regards,
Daz.

'# D.Collins - 14:30 30/12/2011
'# Open the first PowerPoint file found in the same folder as this script, within list of extensions

strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

strFileExts = ".ppt,.pptx,.pps"           ' <== Just add any others you need to this line separated by a comma

arrFileExts = Split(strFileExts, ",")

Set oFolder = fso.GetFolder(strCurrDir)
Set oFiles = oFolder.Files

blFoundOne = False
For Each oFile In oFiles
    For Each sExt In arrFileExts
        If LCase(Mid(oFile.Name, InStrRev(oFile.Name, "."))) = LCase(sExt) Then
            wshShell.Run "powerpnt /s  """ & oFile.Path & """", 1, True
            blFoundOne = True
            Exit For                   '### Remove this Line if you want it to play all one after the other
        End If
    Next
Next

If Not blFoundOne Then
    '### Remove the line below if you do not want it to display a message when a presentation is not found.
    MsgBox "No PowerPoint presentations found in script folder: " & strCurrDir, vbSystemModal + vbExclamation, "No ppt / pptx found"
End If

Open in new window

0
 
markdmacCommented:
I am curious what type of presentations could be randomly presented by your presenter that would create this need?
0
 
MJSNAuthor Commented:
The need is for any Powerpoint extension to be opened using this VB script.  To add, if there are several Powerpoint presentations in the folder, once the first presentation is launched and then completed, the next powerpiont document will kick off...
0
 
Daz_1234Commented:
In that case I think that markdmac and I have provided what you require and two different ways to achieve exactly that!

Daz.
0
 
MJSNAuthor Commented:
Hello Daz, I was wondering could I ask you a question regarding an old posting
0
 
Daz_1234Commented:
Sorry, I've been away a couple of days.

By all means ask, and depending on the question I'll let you know if I think you need to open a new question thread.

Daz.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.