Stewie410

KioskPPT.vbs

Mar 12th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. ' Title:        kioskPPT.vbs
  4. ' Author:       Alex Paarfus <[email protected]>
  5. ' Date:         2018-03-07
  6. ' Based On:     https://tinyurl.com/ybwl2fdp
  7.  
  8. ' Var/Const definitions
  9. Public Const ppAdvanceOnTime = 2            ' Advance using preset timers
  10. Public Const ppShowTypeKiosk = 3            ' Run in "Kiosk" mode: Fullscreen looped
  11. Public Const ppAdvanceTime = 2              ' Amount of time, in seconds, that each slide will be shown
  12. Public Const ppSlideShowPointerType = 4     ' Hide the mouse cursor
  13. Public Const ppSlideShowDone = 5            ' State of the slideshown when finished
  14.  
  15. Public objFSO                               ' Used to work with Files in the File System
  16. Public objPPTCur                            ' Used to store the Current Powerpoint file
  17. Public objPPTNew                            ' Used to store the New/Updated Powerpoint file
  18.  
  19. Public objShow                              ' The Current slide show being presented
  20. Public objPres                              ' The current powerpoint that's open
  21. Public objPPT                               ' The powerpoint application itself
  22.  
  23. ' Open the two files to work with them
  24. Set objFSO = CreateObject("Scripting.FileSystemObject")
  25. Set objPPTCur = objFSO.GetFile("Path\To\Current.ppt")
  26. Set objPPTNew = objFSO.GetFile("Path\To\New.ppt")
  27.  
  28. ' Open the PPT Application
  29. Set objPPT = CreateObject("Powerpoint.Application")
  30. objPPT.Visible = True                       ' Make the Powerpoint application Visible
  31.  
  32. ' -- Start Run -- '
  33. On Error Resume Next                        ' Exits the loop to cleanly close if an error occurs
  34. Do Until Err.Number <> 0
  35.     ' Compare mtime for both files; if update is newer, then update
  36.    If objPPTNew.DateLastModified > objPPTCur.DateLastModified Then
  37.         WScript.Sleep(5000)                 ' Wait for the file to finish saving (5s)
  38.        CopyNew()                           ' Update objPPTCur with objPPTNew
  39.    End If
  40.     Present()                               ' Present objPPTCur
  41. Loop
  42.  
  43. ' Clean up memory and exit
  44. objPres.Saved = True
  45. objShow.Exit
  46. objPres.Close
  47. objPPT.Quit
  48.  
  49. objPPT = Nothing
  50. objPres = Nothing
  51. objShow = Nothing
  52.  
  53. WScript.Quit
  54. ' -- End Run -- '
  55.  
  56. ' Functions
  57. ' CopyNew - Move updated presentation to presentation folder
  58. Sub CopyNew()
  59.     Dim pptFileName
  60.  
  61.     ' Update objPPTCur with objPPTNew
  62.    objFSO.CopyFile objPPTNew.Path, objPPTCur.Path, True
  63.  
  64.     ' Add a backup file to M:\ConfSlideShow\History with Filename = YYYY-M-D_HH-MM.ppt
  65.    pptFileName = Year(Now()) & "-" & Month(Now()) & "-" & Day(Now()) & "_" & Hour(Now()) & "-" & Minute(Now())
  66.     objFSO.CopyFile objPPTNew.Path, "Path\To\History\" & pptFileName & ".ppt"
  67. End Sub
  68.  
  69. ' Present -- Present the PowerPoint Presentation
  70. Sub Present()
  71.     Set objPres = objPPT.Presentations.Open(objPPTCur.Path)
  72.  
  73.     ' Apply configurations, based on above Consts
  74.    objPres.Slides.Range.SlideShowTransition.AdvanceOnTime = TRUE
  75.     objPres.SlideShowSettings.AdvanceMode = ppAdvanceOnTime
  76.     objPres.SlideShowSettings.ShowType = ppShowTypeKiosk
  77.     objPres.Slides.Range.SlideShowTransition.AdvanceTime = ppAdvanceTime
  78.     objPres.SlideShowSettings.LoopUntilStopped = True
  79.  
  80.     ' Display the Slideshow
  81.    Set objShow = objPres.SlideShowSettings.Run.View
  82.  
  83.     ' Trap Loop: runs until SlideShow is in the "Done" state
  84.    Do until objShow.State = ppSlideShowDone
  85.         objPres.SlideShowWindow.View.PointerType = ppSlideShowPointerType
  86.         objPres.SlideShowWindow.Activate
  87.  
  88.         ' Exception Handler -- If an error occurs, exit the trap loop
  89.        If Err <> 0 Then
  90.             Exit Do
  91.         End If
  92.  
  93.         ' File Update Check--same as above, but just to force an update
  94.        If objPPTNew.DateLastModified > objPPTCur.DateLastModified Then
  95.             Exit Do
  96.         End If
  97.     Loop
  98.     objShow.Exit
  99.     objPres.Saved = True
  100.     objPres.Close
  101. End Sub
Add Comment
Please, Sign In to add comment