title: VBA Powerpoint - Auto run on open and run in the background
body: <p>I'm trying to create a powerpoint presentation which will show the number of days since an injury in the workplace.</p>
  
  <p>When the presentation is first opened by the user i'd like a macro to run that prompts for a date to be entered since the last injury. So far for that i have this which appears to work ok:-</p>
  
  <pre><code>Sub EveryDayAccidents()
  Dim injdate As String
  Dim lastdate As String
  Dim injfree As Integer
  Dim BnrMsg As String
  
  'This Macro defines the latest injury date
  
  injdate = InputBox("Please enter last injury date in this format:  dd/mm/yyyy")
  lastdate = injdate
  injfree = DateDiff("d", injdate, Now)
  BnrMsg = injfree
  ActivePresentation.Slides(3).Shapes("Accidents").TextFrame.TextRange = BnrMsg
  End Sub
  </code></pre>
  
  <p>What i'm missing is some code or another sub that will call this code when the presentation is opened.</p>
  
  <p>Will the text box then update when the date changes naturally or will something need to be running in the background to update the text box? The plan is to leave the slides in the presentation running in a loop until an accident occurs then it would be reset and start again.</p>
  
  <p>Any help would be much appreciated!!</p>
  
  <p>EDIT</p>
  
  <p>So now i have this:-</p>
  
  <pre><code>Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
   If SSW.View.CurrentShowPosition = 3 Then
  
       injdate = ActivePresentation.Slides(3).Shapes("Accidents").TextFrame.TextRange
       injfree = DateDiff("d", injdate, Now)
       BnrMsg = injfree
       ActivePresentation.Slides(3).Shapes("Accidents").TextFrame.TextRange = BnrMsg
  
   End If
  End Sub
  </code></pre>
  
  <p>Which does update the slide when the presentation is running... But it is treating the number in the text box as an actual date (65 turns into 05/03/1900) which means my date difference is in the region of 41,600... What i'd like to do is ignore the dates completely for a moment.</p>
  
  <p>If i input a number (say 1) into the text box i would then want that number to increment by 1 each day, i think this code will do that anyway at the moment but i'm lacking the skills to convert :-</p>
  
  <pre><code>injfree = DateDiff("d", injdate, Now)
  </code></pre>
  
  <p>Into </p>
  
  <pre><code>injfree = injfree + 1 when date changes (garbage i know)
  </code></pre>
  
  <p>Please help :)</p>