MJSN
asked on
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.Shel l")
wscript.sleep 60000
objShell.Run "powerpnt /s C:\ExecPPT\Win7-Managed Desktop Environment- Developers_5.0.pptx"
' 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.Shel
wscript.sleep 60000
objShell.Run "powerpnt /s C:\ExecPPT\Win7-Managed Desktop Environment- Developers_5.0.pptx"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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...
This script will open the first .ppt or .pptx file it finds in the same folder as itself, regardless of its name.
Happy Christmas,
Daz.
'# 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
Happy Christmas,
Daz.
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.
Daz.
'# 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
Happy Christmas,Daz.
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:
Daz.
'# 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
Happy Christmas,Daz.
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
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
ASKER
Hello DAz 1234, would it be wise to add pps to the logic as well
Mjsn, have you tried my code? No file version is needed if you use file type.
ASKER
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.
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?
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?
ASKER
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
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.
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
I am curious what type of presentations could be randomly presented by your presenter that would create this need?
ASKER
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...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Daz, I was wondering could I ask you a question regarding an old posting
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.
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.
Open in new window