与 Excel 不同,PowerPoint 没有在OnTimer
此有用的内容。
仅仅做一个循环将导致 100% 的处理器消耗。你可能不想要那个。
在每次迭代中调用Sleep()
将保留处理器时间,但会使应用程序不负责任。你可能也不想要。
所以你真的应该设置一个计时器。如果您可以编写 VSTO 插件,则只需使用 Timer 类,否则自己在 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