Stewie410

AutoPP.vbs

Mar 5th, 2018
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. On Error Resume Next
  2.  
  3. ' AutoPowerPoint VBScript
  4. ' Based on several scripts:
  5. '   Mostly Sog's post on ArsTechnica:   https://tinyurl.com/y8x5shr2
  6. '   ScriptingGuy1, on TechNet:          https://tinyurl.com/yd6zw7zp
  7. '   MJSN's Thread on ExpertsExchange:   https://tinyurl.com/ycrjojb7
  8. '   StephnMoll's post on Idera:         https://tinyurl.com/y7eacxpj
  9. '   Amrita M's PPT to Slideshow Post:   https://tinyurl.com/yb3zm98g
  10. '   Reece's post on SO:                 https://tinyurl.com/y6uq63qm
  11. '   Powerpoint CMD Options:             https://tinyurl.com/ya6lfs25
  12. '   CompPerf Post from XP-Era:          https://tinyurl.com/54pkgn
  13. '   The Scripting Guys' 3rd Post:       https://tinyurl.com/y6vdvqft
  14. '   The Scripting Guys' NewFiles Post:  https://tinyurl.com/mosqnhj
  15. '   Tao's SO Post:                      https://tinyurl.com/yalxkdpu
  16. '   Garry's AHK Post:                   https://tinyurl.com/ydfolmg8
  17. '
  18. ' -
  19. ' Date:         2018-03-02
  20. ' Office Ver:   2016 Home & Business (Standalone Vol)
  21. ' OS:           Windows 7 Home Premium x64
  22. ' -
  23. ' DevEnv:       Windows 7 Professional x64
  24. ' -
  25. '
  26. ' TODO: Restart Presentation w/out reboot
  27. ' TODO: Add support for other file extensions
  28. ' TODO:
  29. '
  30. ' ---------------------------------------------------------
  31. ' Variable Definitions
  32. ' ---------------------------------------------------------
  33. ' Define the filename of your PPT/PPTX file
  34. objFileName = "SalesLeaderBoard.ppt"
  35.  
  36. ' Define Folder to watch for updated file(s)
  37. ' Note, M:\ References \Marketing
  38. objUpdatePath = "M:\ConfSlideShow\"
  39.  
  40. ' Define path to latest PPT file
  41. objExecutePath = "C:\PPTKioskFiles\"
  42.  
  43. ' Define path to last-known-good file
  44. ' Note, M:\ References \Marketing
  45. objLGKPath = "M:\ConfSlideShow\LKGFile\"
  46.  
  47. ' Define if a file runs with preset or user-defined timings
  48. ' 0 == preset (2s per slide)
  49. ' 1 == user-defined
  50. objSlideShowSetting = 0
  51.  
  52. ' Define view time per slide, in seconds
  53. objSlideShowSlideTime = 4
  54.  
  55. ' Build ful paths/names of update and exec files
  56. objFileUpdate = (objUpdatePath & objFileName)
  57. objFileExecute = (objExecutePath & objFileName)
  58. objLKGFile = (objLKGPath & objFileName)
  59.  
  60. ' Set configuration for the slideshow
  61. If objSlideShowSetting = 0 Then
  62.     Const ppAdvanceOnTime = 2
  63. Else
  64.     ppAdvanceTime = objSlideShowSlideTime
  65. End If
  66.  
  67. ' Set Slide Show to display in Kiosk Mode
  68. Const ppShowTypeKiosk = 3
  69.  
  70. ' Enforce the SlideShow to show all slides
  71. Const ppSlideShowDone = 5
  72.  
  73. ' Define FuncObjs here
  74. Set objFSO = CreateObject("Scripting.FileSystemObject")
  75. Set objPPT = createObject("PowerPoint.Application")
  76. Set objPresentation = objPPT.Presentations.Open(objFileExecute, True, True)
  77. Set objSlideShow = objPresentation.SlideShowSettings.Run.View
  78. Set objFile = objFSO.GetFile(objFileExecute)
  79.  
  80. ' ----------------------------------------------------------
  81. ' Functions
  82. ' ----------------------------------------------------------
  83. ' Initialize the project
  84. Function Initialize()
  85.     ' Ensure file exists; else, display error and quit
  86.    Set objFSO = CreateObject("Scripting.FileSystemObject")
  87.     If objFSO.FileExists(objFileExecute) Then
  88.     Else
  89.         WScript.Echo "Error: Your presentation does not exist!"
  90.         WScript.Echo "Please place " & objFileName & " in " & objExecutePath
  91.         WScript.Quit
  92.     End If
  93.     ' Rededine FunObjs
  94.    Set objPPT = createObject("PowerPoint.Application")
  95.     Set objPresentation = objPPT.Presentations.Open(objFileExecute, True, True)
  96.     Set objSlideShow = objPresentation.SlideShowSettings.Run.View
  97.     Set objFile = objFSO.GetFile(objFileExecute)
  98. End Function
  99.  
  100. Function StartPPT()
  101.     ' Open the Presentation & make it visible
  102.    Set objPPT = createObject("PowerPoint.Application")
  103.     objPPT.Visible = True
  104.     Set objPresentation = objPPT.Presentations.Open(objFileExecute, True, True)
  105.  
  106.     ' Execute the above config for the slideshow
  107.    If objSlideShowSetting = 0 Then
  108.         objPresentation.Slides.Range.SlideShowTransition.ppAdvanceOnTime = True
  109.         objPresentation.SlideShowSettings.AdvanceMode = ppAdvanceOnTime
  110.     Else
  111.         objPresentation.Slides.Range.SlideShowTransition.AdvanceTime = ppAdvanceOnTime
  112.     End If
  113.  
  114.     ' Enable Kiosk Mode
  115.    objPresentation.SlideShowSettings.ShowType = ppShowTypeKiosk
  116.  
  117.     ' Define start and end slides to be presented
  118.    objPresentation.SlideShowSettings.StartingSlide = 1
  119.     objPresentation.SlideShowSettings.EndingSlide = objPresentation.Slides.Count
  120.  
  121.     ' Run the Slideshow
  122.    Set objSlideShow = objPresentation.SlideShowSettings.Run.View
  123. End Function
  124.  
  125. Function StopPPT()
  126.     objPresentation.Saved = True
  127.     objPresentation.Close
  128.     objPPT.Quit
  129. End Function
  130.  
  131. Function UpdateFile()
  132.     ' First, though, save and close the presentation
  133.    objPresentation.Saved = True
  134.     objPresentation.Close
  135.     objPPT.Quit
  136.     ' Net, Copy ExecFile to LKGFilePath; overwrite existing if necessary
  137.    objFSO.CopyFile objFileExecute, objLKGFile, True
  138.     ' Delete execFile
  139.    objFSO.DeleteFile objFileExecute
  140.     ' Move updateFile to execFile
  141.    Set objFile = objFSO.GetFile(objFileExecute)
  142.     objFSO.MoveFile objFileUpdate, objFileExecute
  143. End Function
  144.  
  145. ' ----------------------------------------------------------
  146. ' Logic / Run
  147. ' ----------------------------------------------------------
  148. ' Init environment
  149. Call Initialize()
  150.  
  151. ' Start PPT with the above conf
  152. Call StartPPT(objPPT, objPresentation, objSlideShow)
  153.  
  154. ' Run the PPT until sigkill || err
  155. Do Until objSlideShow.State = ppSlideShowDone
  156.     ' If an update file exists, move to execute location && make a backup copy of the current file
  157.    If objFSO.FileExists(objFileUpdate) Then
  158.         Call UpdateFile()
  159.         Call StopPPT()
  160.         WScript.Sleep 7000
  161.         Call StartPPT()        
  162.         Exit Do
  163.     End If
  164.  
  165.     ' Exception Handler
  166.    If err <> 0 Then
  167.         objPresentation.Saved = True
  168.         objPresentation.Close
  169.         objPPT.Quit
  170.         Exit Do
  171.     End If
  172. Loop
  173.  
  174. WScript.Quit
Add Comment
Please, Sign In to add comment