0

I'm interested in creating a slide with powerpoint that will just display a new number in a Shape if theres a new day or time (midnight). I know java programming but haven't done programming in over 6 years now. I've never really used VB.

Dim CurrentTime = TimeValue(now)

Sub If CurrentTime.Now = TimeValue(24:00:00)
 Then updateNum;
      i = i+1

'Then I would like to display 'i' in a shape on powerpoint.

End Sub

Was thinking about doing a continous loop since the file will always be open and will never close.

Or Should I use a timer to countdown the seconds of the day then increment the number?

  • Unless the powerpoint file is always open it will probably never fire. If you're calculating days, just calculate it when the file is open in the appropriate event. Here's a good link to start from: http://msdn.microsoft.com/en-us/library/office/ee814734.aspx – Jesse Sep 30 '12 at 07:46
  • The file will always be open which is why i was thinking a continuous loop. when its a new day I want the number to increase on the slide. Basically its a Continuous Day Counter. CDC. – user1708399 Sep 30 '12 at 12:42
  • I have to ask - can you explain a bit the use case? Having a PowerPoint presentation perpetually open with a number updated daily seems odd, whereas implementing this in an app would be much easier. – Mathias Sep 30 '12 at 16:35

2 Answers2

0

Unlike Excel, PowerPoint doesn't have OnTimer which would be helpful here.

Just making a loop will result in 100% processor consumption. You probably don't want that.

Calling Sleep() on each iteration will preserve processor time, but make the application unresponsible. That you probably don't want either.

So you should really set up a timer. If writing a VSTO addin is okay with you, then just use the Timer class, otherwise make one yourself in VBA:

Option Explicit

Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Private hTimer As Long
Private PrevDate As Date

Public Sub StartTimer()
  If hTimer = 0 Then
    hTimer = SetTimer(0, 0, 1000, AddressOf TimerProc)
  End If
End Sub

Public Sub StopTimer()
  KillTimer 0, hTimer
  hTimer = 0
End Sub


Private Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTime As Long)
  Dim CurDate As Date

  CurDate = Date
  If CurDate > PrevDate Then
    PrevDate = CurDate
    'Put your display code here
  End If
End Sub
GSerg
  • 76,472
  • 17
  • 159
  • 346
0

You can include this in a module in your presentation. It will fire on every slide change during a slide show:

Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
  MsgBox (SSW.View.Slide.SlideIndex)
End Sub

Obviously, replace the MsgBox statement with code to update your text with the current date/time.

This works in PPT 2010 and should work as far back as Office 97, but isn't documented/supported, so MS might remove it whenever the whim strikes them. I don't know whether it works in PPT on the Mac.

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34